shell脚本实现每秒执行任务

一:脚本

#!/bin/sh

while [ true ]; do

/bin/sleep 1

echo 1 >>/root/bo.txt

/bin/date >>/tmp/date.txt

done

 

注意:红颜色里边可以随便加内容,脚本记得给可执行的权限

二:后台运行

nohup /root/beifen/ceshi.sh 2>&1 >/dev/null &

 

或者

nohup sh /root/beifen/ceshi.sh 2>&1 >/dev/null &

 

shell脚本实现每秒执行任务

 

三:确认每秒执行

tail -f /tmp/date.txt

 

shell脚本实现每秒执行任务

 

四:停止脚本并杀死进程

ps -ef|grep ceshi.sh |awk '{print $2}'|xargs kill -9