Kill and Sleep command Not working properly in bash script

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 04:41:14

问题


I have a bash script:

#!/bin/sh
for ((i=0; i<=10; i++)); do 
    ssh "w$i" 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'
done &
pid=$!
sleep 3
kill -9 $pid

I want to kill the ssh within the for loop, if it does not complete within 3 seconds. But my observations are, that the process is not killed and that the loop takes more than 3 seconds to kill.

Can you please help me to correct my script so my script can kill the for loop process after 3 seconds?

来源:https://stackoverflow.com/questions/23005147/kill-and-sleep-command-not-working-properly-in-bash-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!