Using case and foreach in CSH

Here is a simple example of how to use a case and foreach statement in the C shell.

#!/usr/bin/csh

foreach SERVER (`cat hosts.list`)
switch ($SERVER)
case "server1":
case "server2":
echo "NOT shutting down " $SERVER
breaksw
default:
echo Shutting down $SERVER...
/usr/bin/ssh $SERVER init 5
endsw
end

This script will shutdown all servers listed in the file hosts.list, except server1 and server2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s