我有一个bash脚本abcd.sh,我想在其中(/usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat')
5秒后杀死该命令,但是在此脚本中,它要在5秒后杀死该命令sleep
。
#!/bin/sh
/usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat' &
sleep 5
kill $! 2>/dev/null && echo "Killed command on time out"
尝试
#!/bin/sh
/usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat' &
pid=$!
sleep 5
kill $pid 2>/dev/null && echo "Killed command on time out"
更新:
一个有效的示例(无特殊命令)
#!/bin/sh
set +x
ping -i 1 google.de &
pid=$!
echo $pid
sleep 5
echo $pid
kill $pid 2>/dev/null && echo "Killed command on time out"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句