Operating System - HP-UX
1833325 Members
3008 Online
110051 Solutions
New Discussion

favourite sysadmin scripts you always keep around....

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

favourite sysadmin scripts you always keep around....

Hi add your scripts for a sharing to this thread..
top points awarded for TRIED and TESTED scripts!


swcopy:
=======
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x9a6150011d20d6118ff40090279cd0f9,00.html

bdf in MB:
==========
from the forums.. attached

nickel:
=======
html collect system info
http://www.grc.hp.com/docs/nickel/

Later,
Bill
It works for me (tm)
179 REPLIES 179
Justo Exposito
Esteemed Contributor
Solution

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

Hi,

This is a script provided by HP in order to get LVM information.

Regards,

Justo.

PD: good issue!!!
Help is a Beatiful word
Thierry Poels_1
Honored Contributor

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

Hi,

one of the favourite sysadmin scripts should be a cleanup script for /tmp /var/tmp and other (application) temporary directories. As this is server/site specific it's hard to give a standard script.

Another important one is the cfg2html script, which gives you far more information about your server than you ever going to need ;-) (hopefully)
http://members.tripod.com/rose_swe/cfg/cfg.html


regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Animesh Chakraborty
Honored Contributor

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


Hi,
Good examples of script available here.

http://www.introcomp.co.uk/examples/index.html
Did you take a backup?
Steven Sim Kok Leong
Honored Contributor

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

Hi,

My pfsmcd script, many years back. pfsmcd starts the pfs daemons if they have not been started, detects if a CD is already mounted and pfs-mounts the CD (Oracle CD) if it has not been mounted or pfs-unmounts the CD if it has already been mounted.

In addition to root.sh, I had this script added to restricted sam so that the DBA won't come and bother me to mount and unmount Oracle CDs everytime.

Hope this helps. Regards.

Steven Sim Kok Leong

#!/usr/bin/ksh

if ps -ae|grep -v grep|grep pfs_mountd > /dev/null 2>/dev/null
then
echo pfs_mountd already started
else
echo Starting pfs_mountd
nohup /usr/sbin/pfs_mountd &
sleep 5
fi
if ps -ae|grep -v grep|grep pfsd > /dev/null 2>/dev/null
then
echo pfsd already started
else
echo Starting pfsd
nohup /usr/sbin/pfsd &
sleep 5
fi
if /sbin/mount|grep /cdrom > /dev/null 2>/dev/null
then
echo Unmounting /cdrom
pfs_umount /cdrom > /dev/null 2>/dev/null
else
echo Mounting /cdrom
pfs_mount /cdrom > /dev/null 2>/dev/null
fi
Mark van Hassel
Respected Contributor

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

Not a shell script, but a little C program that creates a detailed memory report.
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
Volker Borowski
Honored Contributor

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

Well,
not a shell script, but a complete reference to UNIX:

http://w3.softlookup.com/unix

I am pretty sure you're gonna like chapter 15 Bill :-)

Volker
Volker Borowski
Honored Contributor

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

Oh dear,

sorry for that link. Came accross it via search engine, and it worked fine, but if you call the link directly, you get a whole lot of commercial popups.

Sorry for that, did not intend to.....
Volker
Bill McNAMARA_1
Honored Contributor

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

wooo, apparently I should be earning $4000 per week!
I'm going to have to speak to my boss about that!

15 - Awk, Awk
oh my God ;)

Later,
Bill
It works for me (tm)
Wim Rombauts
Honored Contributor

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

The script thta Jesto has given is great for HP-UX 10.20 machines, but returns an error on HP-UX 11.0 and has some layout issues because of new information that is given by HP-UX 11.0.

Some time ago, i have done the effort to modify the script a very little and to correct the layout issues. For anyone who is interested : feel free to use and enhance it further :
Craig Rants
Honored Contributor

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

There is not much to it, but it always solves the problem of running a script on the last day of the month. Put 28-31 (for days) in your crontab and put this little section in for date determination.

#!/bin/sh

if test `TZ=MET-24 date +%d` = 01
then
exec command
else
exit 1
fi


C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut

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

Can't claim to written this one, but its invaluable notheless...

Produces a map of the lvol locations in vg00

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Tracey
Trusted Contributor

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

I have two favorite scripts that I keep on all machines. This one is user_kill

It gets rid of those nasty users who just won't log off when you ask them to in order to do maintenance. It does keep a few users that you don't accidently want to get rid of.

Tracey
Tracey
Trusted Contributor

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

Here is my second one, it is idle_kill a C program. It clears out your system those users have been idle for too darn long, you can also provide a list of users to ignore (wouldn't want to knock yourself off, eh?)

The exception list is just a file with contents like:

root
oracle
tracey


Tracey
Paula J Frazer-Campbell
Honored Contributor

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

Hi Bill

A small script to ensure that tapes are never missed.

I have it cronned to run on all servers at 16:00 hrs every day.

Change the Email address to suit


-----------------cut here----------------
#!/bin/sh
#############################################
# Check for tape in drive
# PJFC 2002
#############################################
# Check if tape is in Drive (set for correct dev file)
if /usr/bin/mt -t /dev/rmt/0m rew 2>/dev/null ; then
#############################################
echo "----------------------------" >>/tmp/tape-log
date >> /tmp/tape-log
echo "------ Tape in ------" >>/tmp/tape-log
else
#############################################
# Inform if no tape in drive
echo "----------------------------" >>/tmp/tape-log
date >> /tmp/tape-log
echo "------ TAPE NOT LOADED -----" >>/tmp/tape-log
mailx -s "Tape not mounted on N0" paula@avro.co.uk mailx -s "Tape not in on N0" helpdesk@avro.co.uk exit
fi
-----------------cut here----------------

The /tmp/tape-log keeps historical data and the /sysadmin/team just contains the words "Unix Support Team".


Paula
If you can spell SysAdmin then you is one - anon
Deshpande Prashant
Honored Contributor

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

HI
Here is the SysInfo script.

Thanks.
Prashant Deshpande.
Take it as it comes.
Helen French
Honored Contributor

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

Hi,

Here is a script for sending mail, with message body and attachment.

HTH,
Shiju
Life is a promise, fulfill it!
Sanjay_6
Honored Contributor

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

Hi Bill,

Here is one to find the clock speed of the system.

./mhz

Regds
Richard Darling
Trusted Contributor

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

Here are two scripts that I love; first one uses cpio to copy from one system to another, retaining permissions and ownerships. Second one gives a really nice report on EVERYTHING you might want to know about a system.

RD
Alan Riggs
Honored Contributor

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

I use this to centralize common admin tasks. It runs on my admin server and executes a command on any of several preset server groups (specified by server.XXX files).

# cat run
#!/bin/ksh
##############################################################################
#
# THIS SCRIPT RUNS COMMANDS ON REMOTE SERVERS. IT EXPECTS TWO
# COMMAND LINE PARAMETERS:
# $1 SPECIFIES THE EXTENSION OF THE FILE CONTAINING SERVER
NAMES
# $2 CONTAINS THE COMMAND STRING TO RUN ON THE REMOTE SERV
ERS.
#
# CREATED 04/05/00 Alan Riggs
#
##############################################################################
##############################################################################
# ESTABLISH ENVIRONMENTAL VARIABLES
##############################################################################
FILE_BASE=/home/admin/server
EXTENSION=$1
COMMAND=$2

##############################################################################
# USAGE STATEMENT: CHECK FOR EXACTLY TWO COMMAND LINE PARAMETERS
##############################################################################
if [ "$#" -ne 2 ]
then
echo "
usage: run [file extension] [command string]\n
run will execute the command string on one or more remote servers.
The script expects a list of servers in $FILE_BASE.[file extension]
Remember to quote command strings of more than one line.\n "
exit 1
fi

##############################################################################
# RUN THE COMMAND ON THE REMOTE SERVERS
##############################################################################
while read SERVER
do
echo "$SERVER"
remsh $SERVER -n "$COMMAND"
done < "$FILE_BASE"."$EXTENSION"
Alan Riggs
Honored Contributor

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

Here's a short and sweet to locate unallocated physical disks on a server.

# cat find_free_disks.sh
#!/bin/ksh
##############################################################################
#
# THIS SCRIPT FINDS DISKS WHICH NOT PRESENTLY BELONG TO A VOLUME GROUP
#
# CREATED 10/29/99 Alan Riggs
#
##########################################################
set -A DISKS `ls /dev/dsk`

echo "BLOCK SPECIAL FILE\tSIZE\tTYPE"
echo "==================\t====\t===="
for DISK in ${DISKS[*]}
do
pvdisplay /dev/dsk/$DISK >/dev/null 2>&1
if [ $? = 1 ]
then
SIZE=`diskinfo /dev/rdsk/$DISK|grep size|awk '{print $2}'`
TYPE=`diskinfo /dev/rdsk/$DISK|grep type|awk '{print $2 $3}'`
echo "/dev/dsk/$DISK \t$SIZE\t$TYPE"
fi
done
A. Clay Stephenson
Acclaimed Contributor

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

Hi:

My contribution has to be my universal date engine, 'caljd.sh'. It converts a calendar date (or todays's date) to a true (well, almost) Julian day and also does the reverse. It then becomes trivially simple to calculate the number of days between any two dates.

Examples:
# What is the date in MM DD YYYY format 100 days from now?
DATE=$(caljd.sh $(caljd.sh -n 100))
echo "New Date = ${DATE}"

# What is the date in MM DD YYYY format 100 days from now unless that falls on a weekend?
DATE=$(caljd.sh $(caljd.sh -n 100 -x 0 -x 6))
echo "New Date = ${DATE}"

# What is the date in MM DD YYYY format 100 days from now unless that falls on a weekend?
DATE=$(caljd.sh $(caljd.sh -n 100 -x 0 -x 6))
echo "New Date = ${DATE}"

# What is the date in YYYY-MM-DD format 20 days previous unless that fell on a Friday?

DATE=$(caljd.sh -S '-' -y $(caljd.sh -p 20 -x 5))
echo "New Date = ${DATE}"

caljd.sh -u gives full usage.

Regards, Clay


If it ain't broke, I can fix that.
Robert Gamble
Respected Contributor

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

This script can be used to check the output of a 'stat' type command regularly or in a cron.

*NOTE* : Script must be edited for local use!
***********************************************
#!/usr/bin/sh
COMMAND="/$DIR1/$Stat_Like_Command"
LOG_DIR="/$DIR2"

$COMMAND > $LOG_DIR/$COMMAND.current
if [ -e $LOG_DIR/$COMMAND.current ]
then
/usr/bin/diff $LOG_DIR/$COMMAND.current $LOG_DIR/$COMMAND.normal > $LOG_DIR/$COMMAND.diff
if [ -s $LOG_DIR/$COMMAND.diff ]
then
echo "Possible Issue with $COMMAND" | mailx -S $COMMAND your@pager.email.com
cat $LOG_DIR/$COMMAND.diff
else
echo "$COMMAND is OK"
fi
else
echo "$COMMAND could not execute"
fi
***********************************************
Mark Greene_1
Honored Contributor

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

when you need to extract a range of lines from a file and grep won't get them all:

# pg extract
#!/bin/ksh
# 10/08/01
# mark greene
# sed -n 'StartLineNumber,EndingLineNumber' source_file > target_file
# $1=source file, $2=starting line, $3=ending line, $4=target file

if [ $# -lt 4 ]; then
echo "usage: extract source starting_line ending_line target"
exit
fi

SOURCE=$1
START_PAGE=$2
END_PAGE=$3p
TARGET=$4
QUOTE="'"

CMD="-n $QUOTE$START_PAGE,$END_PAGE$QUOTE"

eval "sed $CMD $SOURCE >$TARGET"

exit $?
the future will be a lot like now, only later
Sanjay_6
Honored Contributor

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

Hi,

Here is another one i had downloaded from somewhere, but don't use. thought someone might find it useful.

Regards
sanjay