Shell Programming Beginners Class Lesson 1 - Motivation
February 14th, 2007
I am going to write a few lessons on shell programming for beginners from the basic to the advance. I thought I would write some motivation as I know many people who would benefit greatly from shell scripting but choose not to learn.
Why in the world would you want to learn to use your shell environment as a programming environment?
Instead of doing this:
# ssh -l user host1
user @ host1 ~$ cd /app/path
user @ host1 /app/path$ cp important.conf important.conf.02122007
user @ host1 /app/path$ vi important.conf
user @ host1 /app/path$ exit
# ssh -l user host2
user @ host2 ~$ cd /app/path
user @ host2 /app/path$ cp important.conf important.conf.02122007
user @ host2 /app/path$ vi important.conf
user @ host2 /app/path$ exit
# ssh -l user host3
user @ host3 ~$ cd /app/path
user @ host3 /app/path$ cp important.conf important.conf.02122007
user @ host3 /app/path$ vi important.conf
user @ host3 /app/path$ exit
# ssh -l user host4
user @ host4 ~$ cd /app/path
user @ host4 /app/path$ cp important.conf important.conf.02122007
user @ host4 /app/path$ vi important.conf
user @ host4 /app/path$ exit
# ssh -l user host5
user @ host5 ~$ cd /app/path
user @ host5 /app/path$ cp important.conf important.conf.02122007
user @ host5 /app/path$ vi important.conf
user @ host5 /app/path$ exit
You do something like this:
# echo host1 host2 host3 host4 host 5 | while read HOST; do \
ssh -l user $HOST "cd /app/path && \
perl -i.02122007 -pe 's@^key\s*=\s*val$@key=newval@g' important.conf ; \
egrep '^key' important.conf" ; \
done
key=newval
key=newval
key=newval
key=newval
key=newval
#
Then go get a cup of coffee or get some more work done and then get a raise! If you would like to learn more please read the next article in this series Shell Programming Beginners Class Lesson 2 - Variables.


Leave a Reply