SysAdmin Blog, TechTips and Reviews

An (ex) System Administrator's Blog



Archives Posts

UNIX One-Liners: Some Useful Shell Programs

May 23rd, 2009 by elizar

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… and you’ll be reading a lot of those here….

“Keep It Simple, SysAdmin,” or perhaps just “Keep It Shell Script”, that is one of the motto that every sysdamin knows… They automate, they script, they relax.

Too many system administrators, especially former or frustrated programmers, get involved and distracted creating ad hoc programs that grow until they have a life and a following of their own. These programs generally are written in C, awk, or C shell, have no documentation, and are incomprehensible, even to the author, less than two weeks after being finished.

Read the rest of this entry »

Archives Posts

How To Increment a (Bash/Korn) Variable

January 22nd, 2009 by elizar

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 sure, I will need it again..

Anyway, hours are spent searching for the correct format or syntax on the variable, so here it is:

while [[ $NUMBER != $CNTR1 ]]
do
# Separation.. one file each line
#
head -$CNTR1 list | tail -1 > ./processing/$FILENAME.$CNTR1


# moved (or copy) ‘feedme’ as ‘list’
cp ./processing/$FILENAME.$CNTR1 ./processing/list

## ADD the ‘t’ and ‘x’ logic here
##
awk ‘{print $1}’ ./processing/list > ./processing/cutfile
ACCT=`cut -c1 ./processing/cutfile`
if [ $ACCT !=  1 ]
then
PREFIX=’t’
else
PREFIX=’x’

fi
UID=`awk ‘{print $1}’ ./processing/list`
echo “UID is $PREFIX$UID”
NAME=`awk ‘{print $2}’ ./processing/list`
cat ./processing/list
echo $PREFIX
## END OF T and X Logic

## CHECK if user exists or not
## If New User, Create it
##
cat /etc/passwd | grep $UID
return=$?
if [ $return = 0 ]
then
echo “User account already exist”
exit
else
useradd -d $HOMEDIR$PREFIX$UID -g $GROUPMEM -G $SUPGROUP -s $USERSHELL -c “$COMMENTS$NAME `date ‘+%d%b%y’`” -m $PREFIX$UID
#echo $HOMEDIR$PREFIX$UID $GROUPMEM -G $SUPGROUP -s $USERSHELL -c “$COMMENTS$NAME `date ‘+%d%b%y’`”   -m  $PREFIX$UID
echo “$PREFIX$UID:telus2009” | chpasswd
#echo “$PREFIX$UID:telus2009”
echo “Let’s continue”
fi
CNTR1=$(($CNTR1+1))
sleep 1
done

It’s the bold and red text… Hope it helps someone.

Filed under Scripting having 5 Comments »

I was here...