Operating System - HP-UX
1833451 Members
3096 Online
110052 Solutions
New Discussion

favourite sysadmin scripts you always keep around....

 
SOLVED
Go to solution
Robert Hoey
Advisor

Re: favourite sysadmin scripts you always keep around....

Here's a script that we use to notify us if any filesystems have exceeded 90% usage. It runs every 15 minutes, but the script is setup to only e-mail you once per hour.

-Rob
Robert Hoey
Advisor

Re: favourite sysadmin scripts you always keep around....

Here's another one for those of you who are using Omniback. This script utilizes a text file that contains the schedule for rotating tapes. It then checks if the right tape is in the drive/slot. If no, then an e-mail is sent to the admins reminding them to switch the tapes. It also gives instructions to the on how to cancel a Mount Request if one has been detected.

The format of the text schedule file is:
MMDDYY:TAPENAME

It's been great when I've been out of the office. The other admins are automatically reminded to change the tape.

Thanks.
-Rob
Carlos Fernandez Riera
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

This is the script I wrote this morning.

I am trying to know what disks are used by LVM.

No check for lvmtab done. I think it is usefull for large disks environments.

********

mkdir /tmp/carlos/mapas

for i in /dev/*/group
do
vg=`dirname $i`
vgmap=`basename $vg`
echo $i $vg $vgmap
vgexport -s -m /tmp/carlos/mapas/${vgmap} -p $vg
done


for dsk in /dev/rdsk/*
do
echo $dsk "\c"
dd if=$dsk bs=1024 skip=8 count=9 | dd bs=8 skip=2 count=1 | od -x
done > vgids_alldisks

awk ' $1 ~ "/dev/rdsk" { print $3 $4 $5 $6, $1 }' vgids_alldisks | sort >vgids_bydisk
grep VGID mapas/* | sed -e "s#mapas/##" -e "s/:VGID//" | sort +1.0 > vgids_byvg
join -j1 2 -j2 1 -a 1 -a 2 -e "------" -o 2.2 2.1 1.1 vgids_byvg vgids_bydisk > vgids.lst



*****
unsupported
Bill Hassell
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

OK, there are just too many to choose from so I'll just give y'all the URL:

ftp://contrib:9unsupp8@hprc.external.hp.com/sysadmin/

Look in coolscripts, cronscripts, programs and profiles. TYhe most popular ones (in coolscripts):

bdfmegs (very useful, use -v for details)
ljdisplay (personalize your LaserJet front panel)
lls (long listing sorted by size)
loadmedia (simple
psgrep (grep through the ps listing)
psram (sort all processes by RAM usage)
viman (read man pages with vi)


Bill Hassell, sysadmin
T. M. Louah
Esteemed Contributor

Re: favourite sysadmin scripts you always keep around....

Attached script help Cleanup shared memory segments.

cheers,
t+-
Little learning is dangerous!
Bill McNAMARA_1
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

turning into a nice thread..
some cool scripts!

Later,
Bill
It works for me (tm)
Anthony khan
Frequent Advisor

Re: favourite sysadmin scripts you always keep around....

Hi Bill,
Here is my contribution,

=======================================================================
#!/bin/ksh
# -------------------------------------------------------------------
# prodify -- set the file parameters properly on a subtree for
# production
#
# Anthony Khan 2001
#
# -------------------------------------------------------------------
PROGNAME=`basename $0`
USAGE="
Usage: ${PROGNAME} [-o owner:group] [-u umask] [-v] directory\n
\n
This sets the owner/permissions/etc of all files recursively under\n
the directory into a form suitable for production. The umask is set\n
when the file executes, but does not do much atm.\n"
# -------------------------------------------------------------------
# optional args.
#
OWNER_STRING="prod:xxprod"
UMASK=002
VERBOSE=0
while getopts ":o:u:v" opt
do
case $opt in
o) OWNER_STRING=$OPTARG;;
u) UMASK=$OPTARG;;
v) VERBOSE=1 ;;
\?)
echo $USAGE
exit 1;;
esac
done

shift `expr $OPTIND - 1`

# -------------------------------------------------------------------
# non-optional args
#
DIR=${1:?"Provide a directory"}
# -------------------------------------------------------------------
# steps
#
# umask
umask ${UMASK}
# go to directory
if [ $VERBOSE -gt 0 ]
then echo "cd ${DIR}";
fi

cd ${DIR} || exit 1

# chown
if [ $VERBOSE -gt 0 ]
then echo "Changing ownership...";
fi
chown -R ${OWNER_STRING} . || exit 1

# chmod dirs
if [ $VERBOSE -gt 0 ]
then echo "Changing directory permissions...";
fi

find . -type d -mount -exec chmod 2775 {} \; || exit 1

# chmod files
if [ $VERBOSE -gt 0 ]
then echo "Changing file permissions...";
fi

find . -type f -mount -perm -u=x -exec chmod 4774 {} \; || exit 1
find . -type f -mount ! -perm -u=x -exec chmod 0664 {} \; || exit 1

Kenny Chau
Trusted Contributor

Re: favourite sysadmin scripts you always keep around....

To check my machine status for whole day:

/usr/sbin/sar -u -M > /logging/perf/`date +%b%Y`/cpu`date +%d` 2> /dev/null
/usr/sbin/sar -b > /logging/perf/`date +%b%Y`/buffer`date +%d` 2> /dev/null
/usr/sbin/sar -d > /logging/perf/`date +%b%Y`/disk`date +%d` 2> /dev/null

Regards,
Kenny.
Kenny
SHABU KHAN
Trusted Contributor

Re: favourite sysadmin scripts you always keep around....

Bill,

Here is my favourite.. This was written to check if a particular port on a remote host is alive ..
---------------------------------------
# Author : Shabu Khan/Alan Acevedo
#!/usr/local/bin/perl -w

# Initialize!
use IO::Socket;

$numarg = @ARGV;
if ($numarg != 2) {
print "usage: tcpping \n";
exit 1;
}
$host=$ARGV[0];
$tcpport=$ARGV[1];

# Main
$socket=IO::Socket::INET->new
(
PeerAddr => "$host",
PeerPort => "$tcpport",
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not open port $tcpport.\n";

print "Able to open port $tcpport.\n";
close($socket);

---------------------------------------------

-Shabu
Charles Harris
Super Advisor

Re: favourite sysadmin scripts you always keep around....

Here's one of mine, with some valuable Forum code!

Portscan on a line (almost):


start_port=1
end_port=10000
host=127.0.0.1

if [ $# -eq 0 ]
then
echo "No options supplied, using defaults"
sleep 2
clear
else

echo "Startport = $1, Endport = $2, Host = $3"
export start_port=$1
export end_port=$2
export host=$3
fi

[[ $start_port -gt $end_port ]] && echo "Start Port is Higher than the End Port" && exit
1

portscan ()
{
echo " close"|telnet $host $start_port > /dev/null 2>&1

if [ $? -eq 0 ]
then
echo "Port $start_port is open"
fi
export start_port=$(($start_port + 1))

}

while [ $start_port -lt $(($end_port + 1)) ]
do
portscan
done
Chris Vail
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

This isn't a script per se, but I use it all the time in my scripts. I use it to parse
a multi-line file into fields that I can do something with. Using the example of /etc/hosts:

FILE=/etc/hosts
LENGTH=`wc -l |$FILE|awk '{ print $1 }'`
COUNTER=1

while test $COUNTER1 -le $LENGTH
do
LINE=`head -$COUNTER1 $FILE|tail -1`
FIELD1=`echo $LINE|awk '{ print $1 }'`
FIELD2=`echo $LINE|awk '{ print $2 }'`
# etc.....
COUNTER1=`echo "$COUNTER1 + 1"|bc`
done

Not every Unix supports the READ command, but
all of them support HEAD and TAIL. Therefore
this script can be used across all platforms.
steven Burgess_2
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

Script to check free memory

let x=$(grep -i
physical: /var/adm/syslog/syslog.log | head -1 | awk '{print $7}
')/1048
let z=$(vmstat|tail -1|awk '{print $5}')*4096;let z=$z/1000000
let free=100000/$x*$z
let free=$free/1000
let free=100-$free
echo "$x Mb physical memory \n$z Mb memory free \n$free % used"


take your time and think things through
steven Burgess_2
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

Check host file for entry

#!/usr/bin/ksh
##############################################################################
# Script to grep for host name in /etc/hosts #
##############################################################################

site=$1

while [ ! "$site" ]
do
echo "\nPlease speckify a host name\n"
read site junk
done
grep $site /etc/hosts


take your time and think things through
John Dykes
Occasional Advisor

Re: favourite sysadmin scripts you always keep around....

Another Omniback script.

emails stats for last 2 sessions, tape used for last session, next 10 tapes in the pool, and tapes in poor condition.

One of my first scripts but it works so I don't mess with it.
Kenny Chau
Trusted Contributor

Re: favourite sysadmin scripts you always keep around....

Here is my script to check File system:

bdf > /tmp/fstmplog
num=0
while read fs kbyte used avail percent mount
do
if [ "$mount" != "" ] && [ X"$mount" != X"Mounted on" ] && [ "$mount" != "/cdrom" ] ; then
count=`/usr/bin/echo $percent | cut -d"%" -f 1`
if [ "$count" -ge "96" ] ; then
/usr/bin/echo "$mount reach $percent."
let "num = $num + 1"
fi
fi
done < /tmp/fstmplog
if [ $num = 0 ] ; then
/usr/bin/echo "All File Systems are ok!"
fi

Regards,
Kenny.
Kenny
H.Merijn Brand (procura
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

1. appchk.pl

insert your latest Application CD-Rom into the drive and run this script to see whether it has newer versions of installed software available.

I expect the CD to be mounted on /cdrom (initialized on line 14)
I skip japanese, german,french etc (lines 63 and on)

2. stm.pl

a perl/Tk script to display the system's architecture and print it to a postscript printer

you'll need perl, and the perl modules Tk, Tk::TreeGraph , and Graph
Enjoy, Have FUN! H.Merijn
Glenn L. Stewart
Frequent Advisor

Re: favourite sysadmin scripts you always keep around....

Would it be possible to attach some of these scripts as gz files?
Many of the scripts are being word wrapped to 80 col therefore requiring a bit of debugging before execution.

Thanks

Glenn
Kenny Chau
Trusted Contributor

Re: favourite sysadmin scripts you always keep around....

Here is my script to monitor the cluster:

status=`/usr/sbin/cmviewcl | grep cluster | awk '{print $2}'`
case $status in
up )
/usr/bin/echo "Cluster is $status."
Logging "Cluster is $status." ;;
down )
/usr/bin/echo "Cluster is $status"
Error "Cluster is $status"
code=101
Pager Operator $code
Pager Kenny $code ;;
starting )
/usr/bin/echo "Cluster is $status"
Error "Cluster is $status"
code=102
Pager Operator $code ;;
halting )
/usr/bin/echo "Cluster is $status"
Error "Cluster is $status"
code=103
Pager Operator $code ;;
unknown )
/usr/bin/echo "Cluster is $status"
Error "Cluster is $status"
code=104
Pager Operator $code ;;
* )
/usr/bin/echo "Cluster is $status"
Error "Cluster is $status."
code=105
Pager Operator $code ;;
esac

The Pager function will use mailx to send mail to the pagers. The Error function will log down the error.

Regards,
Kenny.
Kenny
Volker Borowski
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

Hi,
ever had to check filesystems on 5 systems the same time ?
Need to set date/time on 8 boxes concurrently, but no timeserver available ?

What about a call like this:

adsh bdf
adsh date

Not much music in this script, but a very nice tool!
Volker
Bill McNAMARA_1
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

ping!
It works for me (tm)
Pete Randall
Outstanding Contributor

Re: favourite sysadmin scripts you always keep around....

Bill,

Here's one I use when setting up a new system - nothing fancy but it copies over all the system type files that we've customized, modified, tuned, whatever.

Pete
H.Merijn Brand (procura
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

With kmtune as a very valuable tool, it's output is poor.

This is a perl wrapper that makes it's output somewhat more useful.
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

And, forgot, you can select on the command line, using PCRE

N/A
Enjoy, Have FUN! H.Merijn
Nick Wickens
Respected Contributor

Re: favourite sysadmin scripts you always keep around....

I hate setting up new users manually so heres a script originally created by my predecessor to do it, but substantially amended by me to ensure that duplicate UID's are not created across our two systems which means we can move the live user directories over to the development system using service guard. (And before anyone suggests it yes I could use NIS but I did'nt want to :@).

The other invaluable script I run everynight is fairly site specific but I would recommend that everyone has one - Its a script to remotely print out all of the necessary information to recreate the system on a different box following a disaster and its proved invaluable many times (at least for recovery tests). Include output from the following to ensure you have enough information.

vgdisplay -v
bdf
Your last omniback database backup tape No
Full list of backup tapes for at least the last month.
ioscan -fn
print of /etc/fstab
ll /dev/vg??/group (saves working out the minor numbers :@) )
swlist
sysdef (plus a print out of /stand/system)

Anyone else have any suggestions - I do also regualrly print out the LVMCollect script output mentioned in the earlier posting in this thread as it does come in handy for later reference.
Hats ? We don't need no stinkin' hats !!
Rita C Workman
Honored Contributor

Re: favourite sysadmin scripts you always keep around....

Changing password for a group of users....

This is now a favorite of mine. Issue:
I had to mass change the password for a 'specific' group of users (identified by loginname=all cap letters & their password had expired).

What we (Sven Liessem of HP Canada & me) came up with:

Take a dummy account and key in the new password to get the encrypted password...

Here's the script:

newpass=""
cat /etc/passwd | while read line #read /etc/passwd line by line
do
echo $line | grep -q '^[A-Z][A-Z]*:[^:]*,3\.\.\.:' #see if it matches the criteria
if [ $? -eq 0 ]
then #now replace old passwd for new passwd and print line
username=`echo $line | cut -d: -f1`
therest=`echo $line | cut -d: -f 3-`
echo $username:$newpass:$therest
else #print unmodified lines
echo $line
fi
done

Well it worked for me..anyone else would need to edit the grep criteria to suit your needs..

Rgrds,
Rita