以下shell在centos下使用. 

获取一个压缩软件包的version(版本)

huwei@huwei:/work/lnmp$ ll -a php.tar.gz-rw-rw-r-- 1 huwei huwei 18355694  3月 15 14:32 php.tar.gzhuwei@huwei:/work/lnmp$ tar -ztf php.tar.gz|tail -1|awk -F'/' '{print $1}'php-5.6.19

随机密码,对于mysql,不方便使用下划线以及特殊符号,使用mysqldump备份会失败.

passVar=`cat /dev/urandom | tr -dc "a-zA-Z0-9"| fold -w 20 |head -n 1`

检查是否存在mysql用户,如果不存在侧创建

id mysql        if [ $? -ne 0 ]        then                useradd mysql -s /sbin/nologin                /usr/sbin/useradd mysql -s /sbin/nologin        fi