Archives Posts
July 29th, 2008 by elizar
I’m thinking of doing a series of post that will talk about Shell Scripting, scripting tutorial, examples, application… the whole nine yards of Unix/Linux shell scripts/programming.
The topic of shell scripting is a very broad topic and posting one super long post here will take me all day.. or weeks, depending on my mood.
and internet searches.
So, this will be the start of a series of post about Shell scripts and shell programming. Every new post about scripting will be placed below, with link to the appropriate post.
And did a trend search for shell programming, shell scripts, shell tutorial and it’s alright. Though the volume of searches has been decreasing but that’s alright. There are still some.
Perfect!
Archives Posts
June 6th, 2008 by elizar
The last post, was used to chmod a list of home directory.
I used another application for that ‘for..do’ loop again… it’s climbing my favorite script command list..
second only to ‘while…do’..
for X in `ls -last | grep 2006 | awk ‘{print $9}’`
do
rm -rf $x
done
bye bye 2006 directories!
Archives Posts
May 31st, 2008 by elizar
The Bourne shell for loop looks like this:
for arg in list
do
…Handle $arg…
done
Real life application..
# ls -l | awk ‘{print$9}’
user01
user02
user03
user04
user05
user06
user07
user08
user09
# pwd
/home
# for x in `ls -l | awk ‘{print$9}’`
> do
> chown $x $x
> done
# ls -aslt
total 136
.. yeah you know what the output is.. 
Archives Posts
February 9th, 2008 by elizar
draft……. note to self
#!/bin/bash -x
FILE=”/tmp/IAP_sched”
DIR=”/PRA/prod/files/nz/area11/logs/”
FILE2=$(awk ‘{ print $1 }’ $FILE)
echo “*** Nameserver IP ***”
for ip in $FILE2
do
echo “Doing GTL on” $ip
/PRA/prod/scripts/arc/get_log_times *$ip* >> /tmp/output.txt
done
*alias command is not recognize.. hence the full path of ‘glt’
Archives Posts
October 8th, 2007 by elizar
Just want to document it here. A colleague request to kill multiple PID owned by different users. They don’t have any special privilege to kill process other than their own.
Here’s a simple for…loop script that will look for and kill each PID it found.
#!/bin/sh -x
ps -ef | grep nobody | awk ‘{print $2}’ > /tmp/PID
filePID=”/tmp/PID”
for PID in `cat $filePID`
do
kill -9 $PID
done
#
Line 1, tells which shell will execute the script
Line 2, gets all the PID to be killed and store them on a file.
Line 3, assigns a variable for the file
Line 4 to 7 is the for…do loop which basically gets each line on the file, store the value on $PID and then kill whatever value is in it on line 6.
Yucky script. Post a better one.
Thanks.