有用的脚本示例
时间:2010-08-05 来源:zbhdpx
1.检测包是否存在,不存在就重新下载。
cat > list << "EOF" &&
APC-3.0.19.tgz
eaccelerator-0.9.6.1.tar.bz2
libevent-1.4.9-stable.tar.gz for i in `cat list`
do
if [ -s packages/$i ]; then
echo "$i [found]"
else
echo "Error: $i not found!!!download now......"
wget http://docs.linuxtone.org/soft/lemp/packages/$i -P packages/
fi
done
2检测用户是否为root用户
if [ $(id -u) != "0" ]; then
printf "Error: You must be root to run this script!\n"
exit 1
fi 3.检测进程是否运行:
APC-3.0.19.tgz
eaccelerator-0.9.6.1.tar.bz2
libevent-1.4.9-stable.tar.gz for i in `cat list`
do
if [ -s packages/$i ]; then
echo "$i [found]"
else
echo "Error: $i not found!!!download now......"
wget http://docs.linuxtone.org/soft/lemp/packages/$i -P packages/
fi
done
2检测用户是否为root用户
if [ $(id -u) != "0" ]; then
printf "Error: You must be root to run this script!\n"
exit 1
fi 3.检测进程是否运行:
- vim /root/nginx_pid.sh
- #!/bin/bash
- while :
- do
- nginxpid=`ps -C nginx --no-header | wc -l`
- if [ $nginxpid -eq 0 ];then
- /usr/local/nginx/sbin/nginx
- sleep 5
- if [ $nginxpid -eq 0 ];then
- /etc/init.d/keepalived stop
- fi
- fi
- sleep 5
- done
然后置于后台运行 sh /root/nginx_pid.sh &,这种写法是错误的,这样你用root用户logout后,此进程会消失;正确写法为nohup/bin/bash /root/nginx_pid.sh &,附带下注释:如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令。该命令可以在你退出root帐户之后继续运行相应的进程。nohup就是不挂起的意思( no hang up),哈哈,差点老马失蹄了
相关阅读 更多 +