#!/bin/bash function auto_run() { run_name=$(readlink -f "$0") run_path=$(dirname $(readlink -f "$0")) auto_name="test_auto_fun.sh" src=$run_path/$auto_name dst="/etc/rc.d/init.d/$auto_name" chmod +x $run_name rm -f $src rm -f $dst cat >$src<<EOF #!/bin/bash PATH=/sbin:/usr/sbin:$PATH #chkconfig: 2345 20 80 #description:$auto_name nohup $run_name & EOF /bin/cp $src $dst chmod +x $dst chkconfig --add $auto_name chkconfig $auto_name on rm -f $src } function mykill() { while : do killPid=`ps -ef |grep "$1" |grep -v grep | awk '{print $2}'` if [ "$killPid" != "" ]; then killall -9 $1 kill -9 $killPid else break fi done } auto_run nohup ping baidu.com >/dev/null 2>&1 &