Nohup is not working inside a for loop
I am trying to execute commands on multiple linux remote server. I have
written a shell script but it is not able to execute remote command. The
script is correctly reading username and ip from a config file but not
able to execute remote command.
interval==${1:-1}
delay=${2:-1800}
b=Server-
c=1
d=-
a=$(date +%Y-%m-%d-%H-%M)
INDEX=0
while read NAMES[${INDEX}] IP[${INDEX}]
do
((INDEX=$INDEX+1))
done < config
for (( i=0,j=i+1; i<${INDEX}; i++,j++ ))
do
echo "Server $j Username : "${NAMES[i]}
echo "Server $j IP : "${IP[i]}
file=$b$c$d$a
echo "Server $j file name : "$file
nohup ssh ${NAMES[i]}@${IP[i]} 'vmstat -n ${interval} ${delay} >
$file.csv' >& /dev/null &
let c++
done
In config file,entries are like "username ip" :
ajX 11.22.33.44
mnc 55.66.77.88
I don't get any error while executing my script. Output of Script is :
Server 1 Username : ajX
Server 1 IP : 11.22.33.44
Server 1 file name : Server-1-2013-09-18-07-39
Server 2 Username : mnc
Server 2 IP : 55.66.77.88
Server 2 file name : Server-2-2013-09-18-07-39
But on remote servers, commands are not executed but if I execute it
individually
nohup ssh ajx@11.22.33.44 'vmstat -n 1 30 > vmfile.csv' >& /dev/null &
it works fine. Does nohup doesn't work inside for loop or is there some
other way to do the same. Thanks in advance.
No comments:
Post a Comment