selected sample scripts, book references and other notes

books, links and other info

perl one liners
ssh setup
AWK examples
File Tools, more examples
FIND examples
GREP examples
KILL examples
LINUX information
SED examples

Dave Taylor's Wicked Cool Shell Scripts

HP Certified Book

Special Characters

	---------------------------------------------------
	the following are standard special characters:
	
	& ; | * ? ' " ` [ ] ( ) $ < > { } ^ # / \ % ! ~ -

          	 (spaces also have significance)
	---------------------------------------------------

Login test to ensure "su" for security - HP-UX

(note: developed on HP-UX, retyped,  syntax may have minor errors)


# Test to see if the user logging in is trying to use a restricted
#   account and if they are, log them out.  Developed 06/18/1997
#  author: john meister 
#  
case `/usr/bin/who am i | awk '{ print $1 }'`in
    phredrick) if['/usr/bin/who am i | awk '{ print $1 }'`=`/user/bin/whoami`]
	then
	echo "###################"
	echo " Please log in as an authorized user."
	echo "###################"
	/usr/bin/sleep 4
	exit;exit
	fi;;

    infouser) if[`/usr/bin/who am i | awk '{ print $1 }'`=`/usr/bin/whomai`]
	then
	echo "###################"
	echo " Please log in as an authorized user."
	echo "###################"
	/usr/bin/sleep 4
	exit;exit
	fi;;
esac

link to: HP-UX build script


sample script - run from Linux getting info from Solaris & Linux systems

#!/bin/ksh
#   17nov2004   john meister
#  purpose:  script to execute command on all servers - encapulate in quotes
#  must be run from designated master ssh server
USAGE="usage: sh ./runnow.sh , runs command on all systems - NOTE: encapsulate complex commands in quotes"
##################################
#       HEADER and FILE INFO
##################################
CMD="`echo "$1" | tr ' ' '_'  | tr '/' '-' | tr '|' '-' `" ; export CMD
DATE=`date | cut -c 5-11` ; export DATE
FDATE=`/usr/bin/date +%d%b%y-%H%M` ; export FDATE
FNAME="$CMD.$FDATE" ; export FNAME
LOG="/var/apache/htdocs/SystemInformation/$FNAME.txt" ; export LOG
echo " -- $CMD -- on $DATE -- "| tee $LOG     ###### NOTE writes over file when reexecuted ######
echo " ----------------------------------------------- "| tee -a $LOG
##################################
# Solaris 9 systems use ssh
##################################
HOSTS="host1 host2 host3 host4 ...
...host25 host26 host27" ; export HOSTS
#
for x in  $HOSTS
        do
        echo "\n### $x (`ssh $x uname -r` on `ssh $x uname -i | awk -F, '{print $2}'`) ###" | tee -a $LOG
        ssh $x $1 | tee -a $LOG
        done
##################################
# Solaris 8 systems use rsh
##################################
HOSTS8="host28 host29 host30 host31...
...host49 host50 host51 host52" ;  export HOSTS8
#
for x in  $HOSTS8
        do
        echo "\n### $x (`rsh $x uname -r` on `rsh $x uname -i | awk -F, '{print $2}'`) ###" | tee -a $LOG
        rsh $x $1 | tee -a $LOG
        done
#
##################################
echo " ------------- " | tee -a $LOG
echo "webpage:  http://the_server.com/SystemInformation/$FNAME.txt" | tee -a $LOG
echo " ------------- " | tee -a $LOG
mailx -s " $1 (`date +%d%b%y`)" jm < $LOG
##################################
#      ssh $x uptime | awk '{ print "system up " $3 " " $4 " at " $1 " load avg=" $10$11$12$13 }' | tee -a $LOG
#      ssh $x sar | grep Average | awk '{print "sar average is usr_"$2" sys_"$3" wio_"$4" idle_"$5"%"}' | tee -a $LOG
#      echo "System messages ($DATE):" | tee -a $LOG
#      ssh $x cat /var/adm/messages | grep "`date | cut -c 5-11`" | tee -a $LOG
#      rsh $x uptime | awk '{ print "system up " $3 " " $4 " at " $1 " load avg=" $10$11$12$13 }' | tee -a $LOG
#      rsh $x sar | grep Average | awk '{print "sar average is usr_"$2" sys_"$3" wio_"$4" idle_"$5"%"}' | tee -a $LOG
#      rsh $x cat /var/adm/messages | grep "`date | cut -c 5-11`" | tee -a $LOG
##################################
*********************************************************

EMAIL TO: LinuxMeister-at-comcast.net Copyright © 1997-2007 John Meister All rights reserved.