Journal brlancer's Journal: Greater efficiency with 'screen'
A standard sysadmin function will be to run the same command on multiple systems, whether it's installing a new package or modifying a file. Tools like clusterssh have allowed SAs to automate some of this, but it must open a terminal window for each session. I've now found a simple way to do it with screen.
Create a file with a list of your hostnames:
$ cat machinelist.txt
foo
bar
baz
Now, instantiate a screen session:
$ screen -d -m -S test
Populate the screen session with your hosts:
$ while read h ; do
echo $h ; screen -d -r test -X screen -t $h ssh $h ; sleep 3
done < machinelist.txt
(I've had problems without the sleep statement; I think screen runs over itself)
Close (kill) the original screen window, which is not attached to a remote host:
$ screen -d -r test -p 0 -X kill
Now we can run anything we want on each host (virtually) concurrently:
$ while read h ; do
echo $h ; screen -d -r test -p $h -X stuff "groups
" ; done < machinelist.txt