Operating System - HP-UX
1833777 Members
2026 Online
110063 Solutions
New Discussion

favourite sysadmin scripts you always keep around....

 
SOLVED
Go to solution
Justo Exposito
Esteemed Contributor

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

Hi all,

An script to send an e-mail with one or more bodies, one or more enclosed files and subject. To one ore more e-mail address.

Regards,

Justo.
Help is a Beatiful word
Belinda Dermody
Super Advisor

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

Here is one script, that I run each night. Important.sh. It copies all the identified important system files and does ioscans and lvdisplays, pvdisplays and other stuff and puts all the output into a directory and zips it up. Also it copies the zip file over to another system for backup. It comes in handy for system crash or recovery and especially during the cold Installation of HPUX11.00
John Ferrara
Frequent Advisor

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

Here is a cron script that I run daily to check for failed disks on all of my systems.

uname -n > /tmp/stale.log
echo "\n\n" >> /tmp/stale.log
find /dev/vg* -type b -exec /sbin/lvdisplay -v {} \; | grep stale 2>> /tmp/stale.log 1>&2


I then email the stale.log to myself.

John
It was working fine when I left....what did you do?
Nick Wickens
Respected Contributor

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

I get the same problem as Donald above where I am never informed of "leavers". Therefore I created the attached script to email me and the office managers details of all users that have not been used for the last 60 days (set by a variable at the start of the script). It also lets me know of any users that the operators have created that have never logged in (normally because the person never accepted the contract !!)
Hats ? We don't need no stinkin' hats !!
Jordi Gras
Advisor

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

Hi,

Here is a little one to control the data movement in a directory...

#while true
>do ll
>sleep 2
>done

Goodbye!!!
Take it easy...
V. V. Ravi Kumar_1
Respected Contributor

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

hi bill,

here is the one which gets the info about successful/failed or sulogs into a file and send the file in mail every day.

Script name logdetails
----------------------------------------
#!/usr/bin/sh
DIR=

D=`date +%d`
if [ $D -lt 10 ]
then
DATE=`date |awk '{print $2,"",$3}'`
else
DATE=`date |awk '{print $2,$3}'`
fi
last -R | grep "$DATE" > $DIR/goodlog
lastb -R | grep "$DATE" > $DIR/badlog
dt=`date +%m/%d`
cat /var/adm/sulog |grep "$dt" > $DIR/sulog
echo "GOOD LOGS" > $DIR/complog
echo "---------" >> $DIR/complog
sort -k 7,7 $DIR/goodlog >> $DIR/complog
echo >> $DIR/complog
echo "BAD LOGS" >> $DIR/complog
echo "--------" >> $DIR/complog
sort -k 7,7 $DIR/badlog >> $DIR/complog
echo >> $DIR/complog
echo "SU LOGS" >> $DIR/complog
echo "-------" >> $DIR/complog
cat $DIR/sulog >> $DIR/complog
--------------------------------------------
put the follwoing entry in crontab

55 23 * * * /sysadm/cord/shell/logdetails/logdetails.sh;elm -s "Log Details on HPTST" (mail id) < (Your Directory)/complog
Never Say No
V. V. Ravi Kumar_1
Respected Contributor

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

hi bill,
i mentioned the path in crontab which is in my system, its a mistake it should be

55 23 * * * (Your Directory)/logdetails;elm -s "Log Details on " (mail id) < (Your Directory)/complog

which runs everyday at 11:55 pm.

regds
ravi
Never Say No
V. V. Ravi Kumar_1
Respected Contributor

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

hi,

one more small script which sends the mail about file systems which are 90% or more full.
Script name: fscron
--------------------------------------------
#!/usr/bin/sh
bdf|awk '{print $5," ",$6}'|sed 's/%/ /g'|awk '$1>89{print $1," ",$2}'|sed '1d'
--------------------------------------------

put the following entry in crontab

55 8 * * * (your Directory)/fscron > (your directory)/fssize;elm -s "FS Size more than 90 on " (mail id) < (yourdirectory)/fssize

regds
ravi
Never Say No
benoit Bruckert
Honored Contributor

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

Nice things on this page...
Here's my contribution :
A little script to run every nite late, which send an email in case of any big error in omniback backups..
Une application mal pansée aboutit à une usine à gaze (GHG)
Geoff Wild
Honored Contributor

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

Here's one I got from HP, but added some more parameters. It displays memory, cpu, and some krenel parameters.

Rgds...Geoff

cat hpmem
#!/bin/ksh
#
# Taken from the HP/UniGraphics FAQ
# You must be ROOT to execute this since it uses adb to
# examine the running kernel
#
GetKernelSymbol()
{
echo "$1/D" | adb -k $hpux /dev/kmem | tr "\012" " " | read junk junk2 kval
}
hpux=/hp-ux
rev=$(uname -r | cut -d. -f2)
if ((rev > 9)); then hpux=/stand/vmunix ;fi
/bin/uname -a
GetKernelSymbol "processor_count"
print CPU Count: $kval
GetKernelSymbol "itick_per_tick"
let speed=kval/10000
print CPU Speed: $speed MHz
if ((rev > 10)); then
print CPU HW Support: `getconf HW_CPU_SUPP_BITS`-bit
print Kernel Support: `getconf KERNEL_BITS`-bit
GetKernelSymbol "memory_installed_in_machine"
else
GetKernelSymbol "physmem"
fi
let mb=kval*4/1024 # convert pages to MB
print RAM Size: $mb MB
GetKernelSymbol "bufpages"
let mb=kval*4/1024 # convert pages to MB
print bufpages: $mb MB
GetKernelSymbol "maxuprc"
print maxuprc: $kval
GetKernelSymbol "maxvgs"
print maxvgs: $kval
GetKernelSymbol "maxfiles"
print maxfiles: $kval
GetKernelSymbol "max_thread_proc"
print max_thread_proc: $kval
GetKernelSymbol "nfile"
print nfile: $kval
GetKernelSymbol "nflocks"
print nflock: $kval
GetKernelSymbol "nproc"
print nproc: $kval
GetKernelSymbol "ninode"
print ninode: $kval
GetKernelSymbol "vfd_cw"
print shmmax: $kval
GetKernelSymbol "shmmni"
print shmmni: $kval
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

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

Here's 1 more I use to check individual printers (this is used by our operators a lot).

Rgds...Geoff

>cat /opt/hpnpl/bin/lpst
#!/bin/sh
#
# check printer status
# Geoff Wild

if [ $# -lt 1 -o \( $# -gt 1 -a $# -lt 4 \) ]
then
echo "Usage:"
echo "lpst \"printer\""
echo "Example:"
echo "lpst W052"
exit 1
fi
echo " "
/usr/sbin/ping $1 -n 2
echo " "
lpstat -p$1 -v$1
echo " "
echo "Output Requests"
echo "-----------------------------------------------------------"
lpstat -o$1
echo " "
lpstat -r
echo " "
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
V. V. Ravi Kumar_1
Respected Contributor

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

 
Never Say No
Rainer von Bongartz
Honored Contributor

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


I often want to trace and analyse the network traffic from my host to a specific device on the lan.

Using trace_net a.b.c.d will do this

trace_net ( | hostname)

host=$1
echo "Tracing with $host"

rm /tmp/conslog.opts > /dev/null 2>&1
echo "FILTER IP_SADDR $host" >> /tmp/conslog.opts
echo "FILTER IP_DADDR $host" >> /tmp/conslog.opts
nettl -start
nettl -traceoff -e all
nettl -tn pduin pduout -s 1024 -e all | netfmt -c /tmp/conslog.opts -N | grep -v "packet filtered out"
~

He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
V. V. Ravi Kumar_1
Respected Contributor

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

hi,

to identify who is sending large mails and warn them not to block mail queue i use the following script. here it logs all the mail ids, size of mail and date & time if the mail size is more than 1MB. u can keep the same in crontab for every minute to automate.
--------------------------
mailq|awk '$2 > 1048576 {print $2,"\t ",$3,$4,$5,$6,"\t ",$7}' \
|awk '/^[0-9]/{print}' >> /tmp/msizetemp
sort -n /tmp/msizetemp | uniq > /tmp/msize
------------------------------

regds
ravi
Never Say No
V. V. Ravi Kumar_1
Respected Contributor

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

hi

to warn users about today's database backups every time they login, the following script may be useful.
----------------------------
# Database Backup Warning: Script for generating message

TODAY="`date '+%a'`"
VARFILE=(your file)
SRCDIR= (your Directory)
case $TODAY in
Mon ) cp $SRCDIR/bkup.mon $VARFILE; date '+%d-%b-%Y' >>$VARFILE;;
Tue ) cp $SRCDIR/bkup.tue $VARFILE; date '+%d-%b-%Y' >>$VARFILE;;
Wed ) cp $SRCDIR/bkup.wed $VARFILE; date '+%d-%b-%Y' >>$VARFILE;;
Thu ) cp $SRCDIR/bkup.thu $VARFILE; date '+%d-%b-%Y' >>$VARFILE;;
Fri ) cp $SRCDIR/bkup.fri $VARFILE; date '+%d-%b-%Y' >>$VARFILE;;
Sat ) cp $SRCDIR/bkup.sat $VARFILE; date '+%d-%b-%Y' >>$VARFILE;;
*) > $VARFILE;;
esac
cat $VARFILE
----------------------------------------
add the following in /etc/profile
-------------------------------------
tput smso
sh (script path)
tput rmso
------------------------------------
here bkup.mon, bkup.tue etc should exist in the SRCDIR. an example of such file (bkup.mon)is

***********************************************************************

Cold backup of database(database name) will be taken today at 1915hrs.
The ORACLE database (Database name) will not be available for use from
1915hrs onwards till the backup operation is completed.


Thanks & Regards
SYS. ADMIN. GROUP

***********************************************************************

regds
ravi

Never Say No
John Dvorchak
Honored Contributor

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

Not really a script but two commands:

If you have ever had an Ignite and didn't know when the tape was created, without actually restoring the tape. You can issue a couple of commands to read the lif area of a tape and determine when it was created:

verify that the Ignite tape is mounted and rewound:

mt rew (if you are using the default /dev/rmt/0m otherwise mt -t /dev/rmt/1m rew)

then dd off the lif area of the tape to the file /tmp/tapelif:

dd if=/dev/rmt/0m of=/tmp/tapelif bs=2048 count=10

Now list the contents of the file /tmp/tapelif with lifls:

lifls -l /tmp/tapelif

volume ISL10 data size 281239 directory size 3 02/07/05 18:02:25
filename type start size implement created
===============================================================
ISL -12800 16 240 0 02/07/05 18:02:25
AUTO -12289 256 1 0 02/07/05 18:02:25
INDEX BIN 264 1 0 02/07/05 18:02:25
CONFIG BIN 272 35 0 02/07/05 18:02:26
HPUX -12928 312 880 0 02/07/05 18:02:26
INSTALL -12290 1192 26990 0 02/07/05 18:02:33
INSTALLFS -12290 28184 31744 0 02/07/05 18:02:39
FWWKAR BIN 59928 1 0 02/07/05 18:02:39
INSTCMDS BIN 59936 10750 0 02/07/05 18:02:42
SYSCMDS BIN 70688 45488 0 02/07/05 18:02:50
SCRIPTS BIN 116176 42 0 02/07/05 18:02:50

The date is listed as yy/mm/dd so the above tape was created on July 5, 2002 at 6:02PM.
If it has wheels or a skirt, you can't afford it.
Anu Mathew
Valued Contributor

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

Hi Bill,

A script to collect the Total CPU load on systems, if you want data to plot graphs:

#! /bin/sh
# Authored by Anu Mathew on 01.30.2002
###################################################################
# This script reports the total CPU utilization to the calling
# scripts from up101utl, the performance collector.
###################################################################
i="sys1 sys2 sys3 sys4 sys5 sys6 sys7 sys8 sys9 sys10 sys11"
cpuload=/tmp/cpuload.log
error=/perf/error.log
file=/perf/perf.weekly
for i in $i
do
remsh $i /usr/sbin/sar -M 1 10 2>>$error |egrep Average|egrep "system"
> $cpuload
if [ -s $cpuload ]
then
echo "`echo $i ` `date +%a` `date +%x` `date +%H:%M` `cat $cpuload
|awk '{print $6 "\t" 100-$6}' ` " >> $file
else
: # Do nothing
fi
done

Notes:
Schedule interval and customize per requirements.

Thanks

Anu Mathew
Sridhar Bhaskarla
Honored Contributor

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

I wrote this script to quickly look at the lan interfaces their speeds, IPs and the basic network connectivity.

This is particularly useful after a reboot or a maintenance where you want to perform a sanity check if you have quite a number of interfaces.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Yogeeraj_1
Honored Contributor

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

Hi all,

I use this script to split my Oracle Database Export dump file into 4 pieces each going to a different file system.

Thus overcoming File System size limitations on some systems.

Very helpful to me.

NB. Requires Oracle 8.1.x. I use it on Oracle 8.1.7.4.

Best Regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

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

 
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Eric Buckner
Regular Advisor

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

Hi everyone. Here's mine.

ebdf - bdf in KB, MB, or GB sorted by filesystem.

Time is not a test of the truth.
Eric Buckner
Regular Advisor

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

I am required to back up a LOT of Oracle Databases and Applications w/ Omniback. 2 of these are 1 TB each in size and since OB2 doesn't do a good job of balancing the load I wrote my own. The first script here came originally from my EBDF script and creates a sorted by size list of all the filesystems give to it on the command line. I redirect this to an output file for input into my load balancer script.

preloadbal.sh
#!/usr/bin/ksh
#
# @(#) Module: preloadbal.sh Release: 1.2 Date: 07/18/02 Time: 15:37:32
#
# ****
# **** This Script is under Revision Control, do not
# **** modify this script directly without going thru
# **** the revision control system first
# ****
#
# Takes space delimited filesytems as parameters and
# sorts them in numeric order as a precursor to the
# Omniback Load Balancer.
#

typeset -i CNT

if [ $# -ge 1 ]; then
DFFS=$*
else
DFFS=""
fi


CNT=0

df -k $DFFS|
while read LINE; do

if [ "`echo $LINE | cut -c1`" = "/" ]; then
FS=`echo $LINE | cut -f1 -d'('`
TOT=`echo $LINE | cut -f2 -d':' | tr -s ' ' ' ' | cut -f2 -d' '`
let CNT=1
fi

if [ $CNT -eq 2 ]; then
FREE=`echo $LINE | tr -s ' ' ' ' | cut -f1 -d' '`
fi

if [ $CNT -eq 3 ]; then
USED=`echo $LINE | tr -s ' ' ' ' | cut -f1 -d' '`
fi

if [ $CNT -eq 4 ]; then
PCNT="`echo $LINE | tr -s ' ' ' ' | cut -f1 -d' '`%"
let CNT=0
echo "$USED $FS"
fi

let CNT=$CNT+1

done | sort -r -n


The second script is attached and has a command line option of -c for creating the output file. We have a Surestore 6/60 and have 6 LTO drives so you may have to adjust it for the number of drives you have. In a nutshell this script starts w/ the largest filesytem and assigns it to a drive. It then gets the next one and does the same. When all drives have at least 1 filesystem assigned it will then begin to assign each subsequent filesystem to the drive w/ the least amount of data on it until it has all the filesystems done. It then creates a datalist usuable inside of OB as is.

Time is not a test of the truth.
Raimo Lesonen_1
Advisor

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

This one totals the installed hard disks.

Cheers,
Raimo

#!/usr/bin/sh
function disks
{
for i in `ioscan -fnC disk|grep -v floppy|grep rdsk|awk '{print $2}'`
do
diskinfo -b $i
done
}
x=0
for i in `disks`
do
printf "%5.#2f\n" `echo "$i/(1000*1024)"|bc -l `
x=`expr $x + $i`
done
printf "Total disk space %5.2f GB\n" `echo "$x/(1000*1024)"|bc -l`
Ralph Grothe
Honored Contributor

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

Hi Bill,

haven't got time now to have a look at all the favorite scripts posted by all the others in this thread.
So it might be that someone else already posted something similar.
Nevertheless, just a couple of days ago I had to check and possibly set the timeout values of many hundred disks from various of our disk storage subsystems according to different vendor specifications (e.g. EMC calls for 180 secs whereas HITACHI needs 60 secs).
Obviously such repetitive mundane works calls for a script.
So just throwing together a couple of LVM commands in a short time the scriplet you may find attached was made, and in a flick all PVs were set correctly.

Hope this will be of any use to your collection.

Ralph
Madness, thy name is system administration
John Payne_2
Honored Contributor

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

Not really a script, but I always do 'sam -r' on a new box and enable myself for everything. We are a University, and our operations staff is all students. That way, when I go on vacation for a day and come back, and something has happened to the root account, (Happens more often than I would like to admit) I can look like a miracle worker when I get things fixed for them... (Although I really wish they didn't have root, but we're still working on that...)

Hope it helps

John
Spoon!!!!