UNIX

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