Category Archives: Scripting

KSH Script Basics | Special Shell Variables

Just deleted tons of stale, unsused user accounts. Here are some KSH shell basics and special shell variable. I need to Google them up myself to get reminded that ‘$?’ is the output variable for script execution. That is, it’s 0 for successful execution and 1 if there is any error.

UNIX One-Liners: Some Useful Shell Programs

My Favorite One-Liners: Some Useful Shell Programs… But first things first… I would like to note that this aint my list of favorite shell programs.. well, it has become… but what I mean is this aint an original article that I created and posted here.. this is a section from the now defunt, Sysadmin Magazine… … Continue reading

How To Increment a (Bash/Korn) Variable

Ever wonder how to increment a number inside a variable in a bash or korn shell? If you’re the geeky type of guy, I’m sure you know how.. Well, this quick post is sort of like a note to self.. I jsut want to have it handy in case I need it again.. and for … Continue reading

Shell Scripts Tutorials

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 … Continue reading

Used Another ‘For… DO’ Loop

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!

Looping Through a List of Arguments (bourne)

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 # … Continue reading

Store a file output in a variable

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’

Loop Kill Mutiple PID On Bourne Shell

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 … Continue reading