Issue
I want to ssh to a node and run a command there and then exit. This is repeated for all nods. The script is fairly simple
#!/bin/bash
NODES="compute-0-0 compute-0-1 compute-0-2 compute-0-3"
for i in $NODES
do
ssh $i
ls -l /share/apps
rpm -ivh /share/apps/file.rpm
exit
done
But the problem is that, after the ssh, the ls -l
command is missed. Therefore, the command prompt waits for an input!
Any way to fix that?
UPDATE:
I modified the loop body as
ssh $i <<END
ls -l /share/apps
exit
END
But I get
./lst.sh: line 9: warning: here-document at line 5 delimited by end-of-file (wanted `END')
./lst.sh: line 10: syntax error: unexpected end of file
Solution
Try this
#!/bin/bash
NODES="compute-0-0 compute-0-1 compute-0-2 compute-0-3"
for i in $NODES
do
ssh $i "ls -l /share/apps;rpm -ivh /share/apps/file.rpm;exit;"
done
Answered By - user6077173 Answer Checked By - Dawn Plyler (WPSolving Volunteer)