AIX Shell Scripting Made Simple
Shell scripting is much like having a power tool instead of using a screwdriver, although as with everything else, it's always prudent to have the right tool for the right job. You might not need a power tool to screw in a single screw, but if you have 200 screws, you’ll appreciate the power tool.
It’s the same with shell scripting. If you need to pull information from multiple servers, instead of logging into each individually, you can write a basic shell script to perform that function. Let's dissect a basic shell script. This example is a simple script to report OS levels:
#!/bin/sh
#Variables
_list_of_servers="mars earth saturn jupiter"
# Main Code
for _server in $_list_of_servers
do
echo "$_server OS Level:"
ssh $_server "oslevel -s"
echo "\n"
done
Now this script is going to go out and report the OS level from servers: mars, earth, saturn and jupiter. If you run the script ./script.sh you'll get the following output:
mars
6100-06-04-1112
earth
6100-06-04-1112
saturn
6100-06-04-1112
jupiter
6100-06-04-1112
Search our new 2013 Buyer's Guide.
Maximize your IT investment with monthly information from THE source...IBM Systems Magazine EXTRA eNewsletter. SUBSCRIBE NOW.
View past AIX EXTRAs here
Related Articles
Web Exclusive | Versioned WPARs enable legacy applications on POWER7
E-Newsletter | Tips for a Smooth Handoff of Power Systems Knowledge