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

favourite sysadmin scripts you always keep around....

 
SOLVED
Go to solution
V. V. Ravi Kumar_1
Respected Contributor

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

hi,
---------------------------------------------
to get sar details on a machine on the next day, add the follwoing line in the crontab

0 * * * * /usr/lbin/sa/sa1 600 6

this will collect sar details for every 10 minutes and writes a file with the name sa in /var/adm/sa
for ex: for today the file will be "sa19"

to view the details issue
#sar -f /var/adm/sa/sa19
in fact for todays file u can just issue "sar"
for a different file u need full path.
---------------------------------------------
to fine all the files which are more than 5mb
find . -size +5000000c -print
------------------------
regds
Never Say No
Marco Paganini
Respected Contributor

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

I've had so many corruptions happening to this file, along with corrupted individual INDEX files that I decided to write this script.

Just run as

cd /var/adm/sw/products
mv INDEX INDEX.old
indexgen >INDEX

Paga
Keeping alive, until I die.
Marco Paganini
Respected Contributor

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

This one will show your disk status in a sane way. It gets information from bdf, vgdisplay, lvdisplay and pvdisplay to show you a compreehensive status of your disks.

Much nicer to see than digging through [pv|lv|vg]display. :)
Keeping alive, until I die.
Shannon Petry
Honored Contributor

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

Hers is your /tmp, /var/tmp, and general purpose script for cleaning junk. This script was written for CAD/CAM, FEA and CAE machines.
Microsoft. When do you want a virus today?
Mike_305
Super Advisor

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

Hi Bill,

I am not a scriptwriter and I want to thank you for starting this great forum. Why not push HP to give us some space on ITRC, where the SCRIPT GURU???S can put their script online. Sun has the same setup on their website where scripts can be uploaded to their site. Once again thanks for the good information.

Thanks,

Mike
If there is problem then don't think as problem, think as opportunity.
Fragon
Trusted Contributor

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

Hi Bill, I am now studying "Korn Shell programming". It's really a good place for me. Of course I will make a bookmark for this page.
Also thank everybody who give wonderful scripts here.
Good luck to all!

-Gerald-
Grzegorz Malewski
New Member

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

Cheers,
Here???s a little script I wrote for mass adding print queues from file. Especially useful when adding same set of queues on several systems belonging to one SAP R/3 installation.

Thanks,
--Grzegorz


#!/bin/sh
# Massadding printers with definitions in file

/usr/sbin/lpshut
for STRING in `cat $1`; do {
PRTNAME="`echo $STRING | awk -F\; '{print $1}'`"
HOST="`echo $STRING | awk -F\; '{print $2}'`"
PORT="`echo $STRING | awk -F\; '{print $3}'`"
echo "\nadding remote printer $PRTNAME with location $PORT on $HOST"
/usr/sbin/lpadmin -p$PRTNAME -orm$HOST -orp$PORT -mrmodel -v/dev/null -orc -ocmrcmodel -osmrsmodel
/usr/sbin/accept $PRTNAME
/usr/bin/enable $PRTNAME
} done
/usr/sbin/lpsched

“Tell me all the facts of the world about the presence and I will predict the future for you."
blessing k sagonda_1
Occasional Contributor

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

Hi


Here is mine , i use this to archive files sent as attachments through uuencode.

Called from the aliases file
as archive :"|/local/bin/archive.sh"

later ..

#!/usr/bin/ksh
# script to save attached files sent to the aliases archive.
# Author B K Sagonda.
# 22-07-02
# run when they is mail addresed to archive


# SET ENVIRONMENT
. /etc/local.environ
archive_dir=${GLOBAL_BACKUP_DIR}/archives
cd $archive_dir || mkdir $archive_dir && chmod 755 $archive_dir

# END OF ENVIRONMENT

cd $archive_dir
mail_file=./mail_file.$$

cat - > $mail_file

# lets get from where the mail is comming from.
from=`awk '/^From:/ {print $NF}' $mail_file |sed 's///'`

# Lets get Subject .
subject=`awk -F: '/^Subject/ {print $NF}' $mail_file`

# decode the attached file ...
/usr/bin/uudecode $mail_file

# send an e-mail to the user ...
echo "
Your files have been archived.
Thanks.
" | mailx -s"Re:$subject" $from
rm -f $mail_file
jesues is great
Yogeeraj_1
Honored Contributor

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

Hi,

The attached script is from Tom Danzig. It enabled me to check the speed on all cards on my system.

Hope others will find it useful too.

Best Regards
Yogeeraj
============================================================
L1000: home/deg>./speed-lancard.sh
Card at PPA 0 - IP Address: 132.147.160.9 - Speed = 100 Half-Duplex Auto-Negotiation-ON
Card at PPA 1 - IP Address: 192.96.13.3 - Speed = 100 Half-Duplex
Card at PPA 2 - IP Address: Not assigned - Speed = 100 Half-Duplex
Card at PPA 3 - IP Address: 192.96.13.6 - Speed = 100 Half-Duplex
Card at PPA 4 - IP Address: Not assigned - Speed = 100 Half-Duplex
Card at PPA 5 - IP Address: 10.0.0.100 -
L1000: home/deg>
============================================================
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Mike_305
Super Advisor

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

Hi,

Here is script that I think was written by Andreas Voss, one of the forms members and I am not sure if he has posted this in this form. Which mirrors the root volume groups. I found this script very useful. Great script does it all. I hope it???s Ok with Mr. Voss for me to post his work. If I have made mistake by posting this then I am sorry.

Thanks,

Mike
If there is problem then don't think as problem, think as opportunity.
Telia BackOffice
Valued Contributor

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

Hey,
This is a script PERL that i use for getting usefull information about the SAN:
- Disk
- tape

Under this:
- N_port
- wwid
- HW path
- device if tape

#!/usr/bin/perl

open(LSTD,"ls /dev/td*|");
@array=;
chop(@array);
close(LSTD);

foreach $linie (@array) {
print $linie,"\n";
open(FCMS,"fcmsutil $linie get remote all | grep N_Port_id |");
@fcmsArray=;
chop(@fcmsArray);
close(FCMS);
foreach $linie2 (@fcmsArray) {
@arrayHex=split(/ +/,$linie2);
print $arrayHex[6],"\n";
open(FCMSTEST,"fcmsutil $linie get remote $arrayHex[6] | grep World |");
@fcmstestArray=;
chop(@fcmstestArray);
close(FCMSTEST);
foreach $linie3 (@fcmstestArray) {
@fcmstestSplit=split(/ +/,$linie3);
print $fcmstestSplit[7],"\n";
}
@arrayHexSplit=split(//,$arrayHex[6]);
$hex1=join(/""/,$arrayHexSplit[2],$arrayHexSplit[3]);
$hex2=join(/""/,$arrayHexSplit[4],$arrayHexSplit[5]);
$hex3=$arrayHexSplit[6];
$hex4=$arrayHexSplit[7];
$number1=hex($hex1);
$number2=hex($hex2);
$number3=hex($hex3);
$number4=hex($hex4);
@decArray=join('.',"0",$number1,$number2,"255",$number3,$number4,"0");
foreach $linie4 (@decArray) {
print $linie4;
open(IOSCANHW,"ioscan -fuC tape | grep $linie4 |");
@ioscanHardwareAddr=;
close(IOSCANHW);
@ioscanHardwareAddrSplit=split(/ +/,$ioscanHardwareAddr[0]);
if ($ioscanHardwareAddrSplit[2] eq "") {
print "\n\n";
next;
}
open(IOSCANDEVICE,"ioscan -funH $ioscanHardwareAddrSplit[2] | grep BESTnb |");
@device=;
close(IOSCANDEVICE);
foreach $linie5 (@device) {
@deviceSplit=split(/ +/,$linie5);
foreach $linie6 (@deviceSplit) {
if ($linie6 eq "\n") {
print "\n";
next;
}
print $linie6,"\n";
}
}
}
}
}

BR,
Jannik
U.SivaKumar_2
Honored Contributor

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

Hi,
This is a important link which speaks about porting shell scripts.
http://www.raycosoft.com/rayco/support/porting.html
And few shell scripts here.
http://www.introcomp.co.uk/examples/

regards,
U.SivaKumar

Innovations are made when conventions are broken
Scott Hanson_1
Frequent Advisor

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

A script to monitor a file for any changes to owner, group, permissions. Developed because a certain file kept going missing (deleted by naughty code).
Steve Lewis
Honored Contributor

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

My gift to you all is a couple of little programs I knocked up a few weeks ago for my own amusement. They are for parallel multi-threaded zlib compression.

This program will chop a file (or standard input) into blocks of 4 and compress each in parallel. On our 4 cpu N class system it gives gzip standard compression twice as fast as gzip.

WARNING, this program will use up to 400% cpu.

You need to have zlib installed on your system (get it from the porting center) and to compile it you need to use this command:

MP_NUMBER_OF_THREADS=4 cc +O4 +Oparallel -o pzip pzip.c zlib-1.1.4/libz.a -lpthread

Change the zlib.a path to your own installed location.

The uncompression routine will come in the next posting.

You may need to change it for your own purposes, for instance, the compression level.

It isn't compatible with gzip, since I couldn't figure out the format in RFC 1952. Also gzip format requires creation of a CRC which takes time. This program was written to enable pre-compression of backup streams before sending to the device. It helps when you have a small backup window and a lot of data to squeeze onto a small or slow tape device.

To use it, type
pzip < inputstream > outputstream
or use
pzip filename
where it will add a .pz onto the end.
Or even
tar cvf - /directory | pzip | dd bs=128k of=/dev/rmt/1m

It only gives better compression than a tape device if you change the compress2() calls to use standard or maximum compression.

If it fails to compress something it leaves it as it is returning a non-zero code. Files containing random data (entropy) always fail to compress, due their very nature. Most stuff is OK.

It doesn't work with wildcards, so to use on multiple files use xargs or a for loop such as

for F in *.unl
do
pzip $F
done

Zero length files are increased to 16 bytes, but that is mitigated by the large reduction in the size of large files and the speed of the algorithm as a whole.





Steve Lewis
Honored Contributor

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

Further to my previous posting here is the uncompression program. It isn't parallel, since that goes slower than a single stream, but I wouldn't post something that compresses your data without giving you the ability to uncompress it.

Testing was done on various files and diff/cmp have so far shown no difference from the previous uncompressed data to that which has been pzipped and punzipped.

To compile this program use:

cc +O4 -o punzip punzip.c zlib-1.1.4/libz.a
Timo Ruiter
Advisor

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

Hi Bill,

On one of our hosts we have many pseudo-users that have crontabs. I use two very simple but effective scripts to deal with these crontabs:

showcron:
#!/usr/bin/sh
su ${1:?must specify userid} -c "crontab -l"

editcron:
#!/usr/bin/sh
su ${1:?must specify userid} -c "crontab -e"

It saves me a lot of typing.

Timo
Confucius say: he who runs through forrest in straight line will hit tree
Joseph Bague
Frequent Advisor

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

Hi Bill

A simple script that monitor the login session of your server. add this at the end of /etc/profile.

# Notify Administrator for any login session
H=$(hostname)
USR=$(whoami)
TTY=$(who -mR)
echo "$H : $USR logged in at `date` from (`echo $TTY | awk '{print $6}' ` on `echo $TTY | awk '{print $2}'`)" | mailx -s"$H Login Monitor" sysad@yourmail.com

Joseph
Expect nothing but ready for everything
Dietmar Konermann
Honored Contributor

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

Hi...

to get the LVM PVID and VGID from a disk. Please note that each unique ID consists of 2 longs (2 x 4 Bytes). The 1st long is a host ID (uname -i) and 2nd long is a timestamp. So the PVID tells you when some issued a pvcreate from what machine. The VGID does the same for the vgcreate.

PVID e.g::

# echo "0d8200?UY" | adb /dev/dsk/c0t6d0
2008: 2010702141 2002 Jan 2 10:31:16

VGID e.g.:
# echo "0d8208?UY" | adb /dev/dsk/c0t6d0
2010: 2010702141 2002 Jan 2 07:29:06

Regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Dietmar Konermann
Honored Contributor

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

Hi!

find attached my script "cmpdisks" that can be used to scan all disks one ore more nodes for their LVM/VxVM IDs. It then groups the information into a table... especially useful to get get an idea about shared devices in clusters and SANs.

It also adds information about how the disks appear in /etc/lvmtab.

Example:


cmpdisks nero lola
Password (grcdg319.grc.hp.com:root):
Scanning host grcdg319 ....................
Scanning host hprtdd32

***** LVM-VG: 0557706517-0957278060
1 hprtdd32:c1t0d0 0557706517-0957278059 0/0/1/1.0.0 SEAGATE/ST39103LC (0x05/vg11.00/0557706517-0957278060)

***** LVM-VG: 0557706517-0986205681
1 grcdg319:c4t1d0 0630309352-0968061502 0/12/0/0.1.0 SEAGATE/ST118202LC (0x02/vgsap/0557706517-0986205681)
grcdg319:c5t1d0 0630309352-0968061502 0/12/0/1.1.0 SEAGATE/ST118202LC (0x02/vgsap/0557706517-0986205681)
hprtdd32:c4t1d0 0630309352-0968061502 0/6/0/0.1.0 SEAGATE/ST118202LC (0x01/vgsap/0557706517-0986205681)
hprtdd32:c5t1d0 0630309352-0968061502 0/6/0/1.1.0 SEAGATE/ST118202LC (0x01/vgsap/0557706517-0986205681)
2 grcdg319:c4t0d0 0630309352-0968061503 0/12/0/0.0.0 SEAGATE/ST118202LC (0x02/vgsap/0557706517-0986205681)
grcdg319:c5t0d0 0630309352-0968061503 0/12/0/1.0.0 SEAGATE/ST118202LC (0x02/vgsap/0557706517-0986205681)
hprtdd32:c4t0d0 0630309352-0968061503 0/6/0/0.0.0 SEAGATE/ST118202LC (0x01/vgsap/0557706517-0986205681)
hprtdd32:c5t0d0 0630309352-0968061503 0/6/0/1.0.0 SEAGATE/ST118202LC (0x01/vgsap/0557706517-0986205681)

***** LVM-VG: 0557706517-0986307905
1 hprtdd32:c2t0d0 0557706517-0986307878 0/0/2/0.0.0 SEAGATE/ST39103LC (0x00/vg00/0557706517-0986307905)

***** LVM-VG: 0557706517-1013696807
1 grcdg319:c4t8d0 0557706517-1013696757 0/12/0/0.8.0 SEAGATE/ST118202LC (n/a)
grcdg319:c5t8d0 0557706517-1013696757 0/12/0/1.8.0 SEAGATE/ST118202LC (n/a)
hprtdd32:c4t8d0 0557706517-1013696757 0/6/0/0.8.0 SEAGATE/ST118202LC (0x03/vg_bind90/0557706517-1013696807)
hprtdd32:c5t8d0 0557706517-1013696757 0/6/0/1.8.0 SEAGATE/ST118202LC (n/a)

***** LVM-VG: 0557706517-1015584303
1 hprtdd32:c8t12d0 0557706517-1015677736 0/3/0/0.8.0.255.1.12.0 SEAGATE/ST136403FC (n/a)
2 hprtdd32:c8t13d0 0557706517-1015677741 0/3/0/0.8.0.255.1.13.0 SEAGATE/ST136403FC (n/a)

***** XXX: UNCLAIMED
1 grcdg319:c0t6d0 unknown ??? unknown/unknown
grcdg319:c8t12d0 unknown ??? unknown/unknown
grcdg319:c8t13d0 unknown ??? unknown/unknown

***** XXX: ZEROSIZE
1 grcdg319:c0t1d0 unknown 0/0/1/0.1.0 HP/DVD-ROM 304
grcdg319:c4t10d0 unknown 0/12/0/0.10.0 SEAGATE/ST118202LC
grcdg319:c5t10d0 unknown 0/12/0/1.10.0 SEAGATE/ST118202LC



(hope, there will be no wrapping :-)

Regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Bill McNAMARA_1
Honored Contributor

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

a useful tip I found on the HP web that I thought I should share...


-- finding mem leaks from cli

You can monitor for memory leaks from the command line. Assuming your process is running in background or as a daemon, identify the PID by:

# ps -ef | grep
# # Note the PID
# #
# # in what
# # follows.

# export UNIX95=1 # Turns on XPG4
# # behavior of 'ps'
# # (needed for -o
# # option to work)

Now display physical and virtual size of the process:

# ps -p -o sz,vsz,pid,state

If there is a memory leak, the values of sz (physical pages used) and vsz (virtual pages used) will gradually increase while the code executes.



Later,
Bill
It works for me (tm)
Adrian Singh
New Member

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

Hi,

here is a wonderful script that does the folowing:

shows the current time
the total uptime of the system
the run queue averages for the last 1, 5, 15 mins
total number of users logged on to the system
lists all users logged in
shows what terminal there on
shows what command they are running
tells you how long they have been idle

and heres the script:

----------->8 cut
#!/bin/ksh
w
----------->8 cut

;)
HPUX-- Solaris++
Vicente Sanchez_3
Respected Contributor

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

Hello Bill,

This can be a good place to visit:

www.shelldorado.com

Regards, Vicente
Bill McNAMARA_1
Honored Contributor

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

Attached is a script that gets screenshots from X displays. xhost is used a little insecurely, however, you've got firewalls right?!
Useful for remote training.
xwatchwin from hpux.cs.utah.edu does much the same (when it works)
as does qnc, hpvc and sharedx with a little more configuration.

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

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

attached is a more complete - in terms of error return of the xwd/xwud script.

just execute it it for command line options.

Later,
Bill
It works for me (tm)
Dietmar Konermann
Honored Contributor

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

Just used the following to fix garbled permissions on a system. The script takes a SD software selection and performs chown/chmod commands according to the IPD.


#!/usr/bin/sh
# fix permission/ownership according to IPD

[ "$#" -lt 1 ] && print "Usage: $0 [software_selections]" && exit 1

swlist -l file -a type -a mode -a owner -a group $@ |while read fset path type mode owner group dummy; do
if [ "$type" = f -o "$type" = d ]; then
print "Fixing ${path}: $mode $owner $group"
chown $owner:$group $path
chmod $mode $path
fi
done

Regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)