问题
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