This script is intended to allow you to simultaneously run a command on a set of remote hosts in a single gnome-terminal tabbed window. It runs it through screen so if it's a long process it's immune to network failures.
The command string gets built ok, but when it comes to executing the gnome-terminal command, it chokes with
Quote:
Argument to "--command/-e" is not a valid command: Text ended before matching quote was found for ". (The text was '"ssh')
|
If you copy/paste the "Running: gnome-terminal" line, it works as expected.
I'm pretty sure the problem is with the commandline variable expansion, but dont know what else to try.
Another thing I'd like to be able to do is keep the shell open after the command finishes. Right now, I just get "screen terminated" and the gnome-terminal tab says bye-bye.
Thanks in advance...
Code:
#!/bin/bash
if [ -z "$1" ]; then
echo -e "Usage:\n $0 \"command\"\n"
exit 1
fi
hosts="localhost localhost localhost"
command="'$1'"
commandline=""
for h in $hosts; do
commandline="$commandline --tab -e \"ssh -t root@$h screen -t $h -L $command\""
done
echo "Running: gnome-terminal $commandline"
/usr/bin/gnome-terminal "${commandline}"
Code:
$ ./screenIt "yum check-update"
Running: gnome-terminal --tab -e "ssh -t root@localhost screen -t localhost -L 'yum check-update'" --tab -e "ssh -t root@localhost screen -t localhost -L 'yum check-update'"
Argument to "--command/-e" is not a valid command: Text ended before matching quote was found for ". (The text was '"ssh')
$ gnome-terminal --tab -e "ssh -t root@localhost screen -t localhost -L 'yum check-update'" --tab -e "ssh -t root@localhost screen -t localhost -L 'yum check-update'"