Operating System - HP-UX
1833017 Members
2063 Online
110048 Solutions
New Discussion

Re: favorite sysadmin scripts you always keep around [2]

 
SOLVED
Go to solution
Lisa  Mauer
Regular Advisor

Re: favorite sysadmin scripts you always keep around [2]

Here is one (with a config file), I didn't write it, just modified it a bit. Don't know who wrote it - sorry, but it has proven VERY helpful.

####################################################################
# This configuration file is set up for the script filesysmon.
# Set up all file systems and percentage full before an email
# will go out to the admins of the server.
# 08/28/02 Lisa Mauer
####################################################################
# MAX_TRESH is the max thresh before sending out a critical message
MAX_THRESH=98

# THRESH for each FS is the THRESH before sending a message
FS[1]=/ ;THRESH[1]=60
FS[2]=/stand ;THRESH[2]=60
FS[3]=/var ;THRESH[3]=85
FS[4]=/usr ;THRESH[4]=95
FS[5]=/tmp ;THRESH[5]=85
FS[6]=/opt ;THRESH[6]=80
FS[7]=/opt/savelog ;THRESH[7]=75
FS[8]=/opt/oradata ;THRESH[8]=75
FS[9]=/opt/dbutil ;THRESH[9]=75
FS[10]=/opt/app/oracle ;THRESH[10]=80
FS[11]=/opt/gpdev/80 ;THRESH[11]=97
FS[12]=/home ;THRESH[12]=95

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


###########################################################################
# This script monitors file systems for available disk space on any server
# File systems and percentages are set up in the config file.
# To change the configuration use /usr/local/bin/disk_space.conf
# Currently set up in cron to run every 15 minutes.
#
# 08/28/02 Lisa Mauer
###########################################################################

# Debugging purposes
#set -x

PATH=/usr/bin:/usr/sbin
CONF_FILE=/usr/local/bin/disk_space.conf

# Source default env vars
. ${CONF_FILE}
# Count number of FS to check
i=${#FS[*]}
# echo max - $MAX_THRESH
# Check each Filesystem
while [ $i -gt 0 ]
do
PCT=`bdf ${FS[$i]} | grep -v Filesystem | cut -c 45-47`
if ((PCT>THRESH[$i]))
then
echo " ${THRESH[$i]} "
if (("${PCT}>${MAX_THRESH}"))
then
echo "Subject:Out of disk space ${FS[$i]} on `hostname`!!!!

Out of disk space on ${FS[$i]} on `hostname`" |sendmail admin@yourcompany.com admin2@yourcompany.com
else
echo "Subject:Threshold exceeded ${FS[$i]} on `hostname`!!!!

Threshold exceeded on ${FS[$i]} on `hostname`" | sendmail admin@yourcompany.com admin2@yourcompany.com
fi
fi
let i=i-1
done
exit 0

Peter Heinemann
Frequent Advisor

Re: favorite sysadmin scripts you always keep around [2]

For folk using EMCs, this shows the mappings of disk device file->EMC LUN -> volume group ->logical volume (if assigned)

/dev/rdsk/c4t7d2 :9803A000 vgdw lvarch0
/dev/rdsk/c4t7d3 :9803B000 vgdw lvarch1
/dev/rdsk/c4t7d4 :9803C000

NOTE:

-assumes EMC's inq utility is installed an in your path.
-attachement includes three files: emcuse.sh, lvassign.sh, and lvassign.prl that you'll need to save seperately.
- if you're multi-pathing, the LUN ids will repeat with the alternate disk device files.
Elif Gius
Valued Contributor

Re: favorite sysadmin scripts you always keep around [2]

I have just a simple script to collect some information about a cluster...
Bambang Lestari
Occasional Contributor

Re: favorite sysadmin scripts you always keep around [2]

This script is used to create bulk file systems in one shot.
Tom Jackson
Valued Contributor

Re: favorite sysadmin scripts you always keep around [2]

Hey Bill:

I have two. The first one sets up a volume group, the second one mirrors the system disk. There are a couple tricks to getting it to work. You need to create fstab and mirror scripts for each vg.

fstabs:
/dev/vg00/lvol3 / vxfs delaylog 0 1
/dev/vg00/lvol1 /stand hfs defaults 0 1
/dev/vg00/lvol4 /tmp vxfs delaylog 0 2
/dev/vg00/lvol5 /home vxfs delaylog 0 2
/dev/vg00/lvol6 /opt vxfs delaylog 0 2
/dev/vg00/lvol7 /usr vxfs delaylog 0 2
/dev/vg00/lvol8 /var vxfs delaylog 0 2

/dev/vg02/lvol3 / vxfs delaylog 0 1
/dev/vg02/lvol1 /stand hfs defaults 0 1
/dev/vg02/lvol4 /tmp vxfs delaylog 0 2
/dev/vg02/lvol5 /home vxfs delaylog 0 2
/dev/vg02/lvol6 /opt vxfs delaylog 0 2
/dev/vg02/lvol7 /usr vxfs delaylog 0 2
/dev/vg02/lvol8 /var vxfs delaylog 0 2

create vg:
mkdir /dev/vg02
mknod /dev/vg02/group c 64 0x020000
pvcreate -fB /dev/rdsk/c2t12d0

mkboot /dev/rdsk/c2t12d0
mkboot -a "hpux -lq" /dev/rdsk/c2t12d0
lifcp /dev/rdsk/c2t12d0:AUTO -

vgcreate -e 5000 -s 8 -l 8 -p 8 /dev/vg02 /dev/dsk/c2t12d0
lvcreate -L 112 -s y -C y -r n -n lvol1 /dev/vg02
lvcreate -L 4096 -s y -C y -r n -n lvol2 /dev/vg02
lvcreate -L 144 -s y -C y -r n -n lvol3 /dev/vg02
lvcreate -L 1024 -s y -n lvol4 /dev/vg02
lvcreate -L 4096 -s y -n lvol5 /dev/vg02
lvcreate -L 2744 -s y -n lvol6 /dev/vg02
lvcreate -L 1544 -s y -n lvol7 /dev/vg02
lvcreate -L 1544 -s y -n lvol8 /dev/vg02

lvlnboot -b /dev/vg02/lvol1
lvlnboot -r /dev/vg02/lvol3
lvlnboot -s /dev/vg02/lvol2
lvlnboot -d /dev/vg02/lvol2

After setting up the above files, the mirror script runs every noght to create a new system disk. I set this up as my alternate boot device. I can boot from alt without having to modify any files, then I can reboot from the PRI device any time, again without editing any files.

Tom
Tom Danzig
Honored Contributor

Re: favorite sysadmin scripts you always keep around [2]

Here's one I wrote to get LAN card throughputs by interface.

"netstats -h" for usage.
OneNeck UNIXSA
Frequent Advisor

Re: favorite sysadmin scripts you always keep around [2]

A Perl script that parses some system logs and looks for known errors.
Kim Kendall
Regular Advisor

Re: favorite sysadmin scripts you always keep around [2]

LOVE THIS ONE.... (re)names the window title bar and/or icon name to $1 and offers to telnet to $1....

Usage: (how I mostly use it ;) )

title nodename

Will name the window $ icon to "nodename" and will ask if you want to telnet to nodename.

Makes it real nice to open a telnet session into all my key servers and close to an icon. Then I can know by their names exactly which icon will get me into which server.
Michael Tully
Honored Contributor

Re: favorite sysadmin scripts you always keep around [2]

A quick one-liner that I find useful to examine the /var/adm/sulog file for bad attempts to 'root'
Anyone for a Mutiny ?
H.Merijn Brand (procura
Honored Contributor

Re: favorite sysadmin scripts you always keep around [2]

As an example how perl can save you time, I ran into a project where someone used dreamweaver to change the charset for jsp files on HP-UX (over samba) that acted as scripts through a server.

A colleage said that changing all files using dreamweaver would not only take too much time (250+ files), but could be done much easier with vi.

I overheard, and typed this line:

# perl -pi -e's/charset=iso-8859-1/charset=utf-8/' *

Done in 15 seconds (including the typing)
Enjoy, Have FUN! H.Merijn
Donald Kok
Respected Contributor

Re: favorite sysadmin scripts you always keep around [2]

Hi,
I am to lazy to type
ps -ef | grep xxx | grep yyy | grep zzz
so I made psgrep:

case $# in
1) ps -ef | grep $1 ;;
2) ps -ef | grep $1 | grep $2 ;;
3) ps -ef | grep $1 | grep $2 | grep $3 ;;
4) ps -ef | grep $1 | grep $2 | grep $3 | grep $4 ;;
5) ps -ef | grep $1 | grep $2 | grep $3 | grep $4 | grep $5 ;;
*) echo " Thats much parameters " ;;
esac

Greetzz
Donald
My systems are 100% Murphy Compliant. Guaranteed!!!
Donald Kok
Respected Contributor

Re: favorite sysadmin scripts you always keep around [2]

put in cron :
find / -print > /tmp/filelist

make an script filegrep:

case $# in
1) cat /tmp/filelist | grep $1 ;;
2) cat /tmp/filelist | grep $1 | grep $2 ;;
3) cat /tmp/filelist | grep $1 | grep $2 | grep $3 ;;
4) cat /tmp/filelist | grep $1 | grep $2 | grep $3 | grep $4 ;;
5) cat /tmp/filelist | grep $1 | grep $2 | grep $3 | grep $4 | grep $5 ;;
*) echo " Thats much parameters " ;;
esac

You now can quickly scan your filesystem for files like:
filegrep xxx yyy zzz

Greetzz
Donald
My systems are 100% Murphy Compliant. Guaranteed!!!
Ian Dennison_1
Honored Contributor

Re: favorite sysadmin scripts you always keep around [2]

This script wot I wrote, to run every Friday afternoon to check that Ignites will work the next morning ( > 32MB space in /var/tmp, tape in drive, all entries mounted in /etc/fstab).

2 parts - Refreshignite.sh runs on the management server, copies out the checkignite.sh script and runs it.

Share and Enjoy!
Building a dumber user
Kellogg Unix Team
Trusted Contributor

Re: favorite sysadmin scripts you always keep around [2]

Here is a small script to change ownership of files from one uid to another - is useful when mass uid synchronization is going on!
work is fun ! (my manager is standing behind me!!)
fg_1
Trusted Contributor

Re: favorite sysadmin scripts you always keep around [2]

Hi all

Figured its time to post another one as we
should not let this thread fall by the wayside.

I am posting a copy of a script here which i have that does an archive of certain logfiles on the system keeping a specified amount of
days for the logfile specified. This script
will also zip up the old logfiles consolidating
space.

I encourage more people to post to this thread
as it is probably one of the greatest repository's of scripts on the web.

Gl 2 all.
Gary Yu
Super Advisor

Re: favorite sysadmin scripts you always keep around [2]

Encouraged by Frank, here I post a small script that can tail as many lines as you like(a workaround of the shell buffer issue which cause tail -n can only show limited lines)

I got the idea from this forum(http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xbe2606350fe2d61190050090279cd0f9,00.html) and I would like to share it with those may encountered the same problem.

###########script start from here #######
if [ $# -ne 2 ]
then
echo "Usage: $0 lines filename_to_tail"
exit 1
else
typeset -i LINES=`wc -l $2 | awk '{print $1}'`
typeset -i STARTS
STARTS=$(($LINES-$1+1))
sed -n ${STARTS},${LINES}p $2
fi

############script end here ###############
Ben Sachs_1
Advisor

Re: favorite sysadmin scripts you always keep around [2]

This is a great thread!!

Here is my small contribution. A perl script which just gives output of your /home directory usage:


/home's total usage is 115933 kb
/home/user (2902 kb) is 2%
/home/user (10363 kb) is 8%
/home/user (6189 kb) is 5%
/home/user (2732 kb) is 2%
/home/user (2444 kb) is 2%

...etc

-Ben
Kellogg Unix Team
Trusted Contributor

Re: favorite sysadmin scripts you always keep around [2]

Here is a simple script for daily rotation of mail log - useful for smtp servers. Can be combined with find command to delete log files older than, say, 2 months.

Thanks
...Manjeet
work is fun ! (my manager is standing behind me!!)
Jean-Louis Phelix
Honored Contributor

Re: favorite sysadmin scripts you always keep around [2]

hi,

This script checks if a patch is :
- already installed on a system
- not present on a system
- superseded by another patch already on the system (and display the superseding patch).

Sometimes it can show you that you don't need to install a requested patch. This tool has a -u option for usage but works only for 11.00 and later (it uses show_patches)

Regards
It works for me (© Bill McNAMARA ...)
Khalid A. Al-Tayaran
Valued Contributor

Re: favorite sysadmin scripts you always keep around [2]


Hi,
A typing mistake again...

This is not a script really but a combination of pwd an ll or ls.

Good luck.
Bill Hassell
Honored Contributor

Re: favorite sysadmin scripts you always keep around [2]

Here's a 1-liner to sort files by size:

ll | sort -rnk5 | more

And attached is a script to find running programs by name. It does not use grep which eliminates all the errors caused by matching strings in other fields. I call it psbyname. Try it with:

psbyname sh

and compare to:

ps -ef | grep sh


Bill Hassell, sysadmin
Tom Jackson
Valued Contributor

Re: favorite sysadmin scripts you always keep around [2]

Here's one that generates an inactivity report and mails it to you.

Tom
Tom Jackson
Valued Contributor

Re: favorite sysadmin scripts you always keep around [2]

Here's one that fixes all records in a sub dir. Does substitutions and deletes for records containing patterns.
Tom Jackson
Valued Contributor

Re: favorite sysadmin scripts you always keep around [2]

Here's one that does a dos2ux for all files in a sub dir. You can modify it to go the other way (ux2dos).

Tom
avsrini
Trusted Contributor

Re: favorite sysadmin scripts you always keep around [2]

Hi,
This is a small script to get the running processes
to a file when system load exceeds threshold.

You can change the threshold value and the no. of processes
to get into file according to
your system need.

This file gives us what system is running when loads goes high.

ENjoy.
Srini.
Be on top.