Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
User Journal

Journal brlancer's Journal: Greater efficiency with 'screen'

I've been a screen fanatic for years. I have a tendency to work on a great number of "things" simultaneously, but I hate having lots of terminal windows hanging around. Tack on the ability to access sessions remotely (or to preserve them in case of an X crash) and screen is essential.

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

Real Programmers don't eat quiche. They eat Twinkies and Szechwan food.

Working...