Operating System - HP-UX
1844276 Members
2421 Online
110230 Solutions
New Discussion

Re: favorite sysadmin scripts you always keep around (3)

 
SOLVED
Go to solution
Ralph Grothe
Honored Contributor

Re: favorite sysadmin scripts you always keep around (3)

Hi Bill,

not that I would consider this script to be one of my favorites.
I just dare to post this quick'n'dirty Perl script here because it is so HP-UX related it wouldn't be of any use on any other platform (you might even rightly question the usefulness on HP-UX)
And this forum deals about HP-UX, right?

We occasionally get network bottlenecks on some of our database servers during high peak.
Before I got the netperf tool I needed something quick to give me a rough estimate on the NICs' throughput and packet rates.

Lacking OID, MIB, and ASN knowledge of the SNMP to have done it properly I just took the MIB stats the lanadmin command is dumping.

Since the lanadmin command may even be issued by a non-root user (as long as one doesn't wish to set anything), this process can safely be run under a harmless euid.

Because of our special MC/SG cluster environment I do a little detour over the cmviecl command to obtain the active NIC.
But this isn't really necessary, and one can easily omit this command in the script.
The same reason holds for the parsing of the process table in one column in order to get the number of Oracle Net8 connections to get a rough overview of the database's connection handles.
This part can also easily be discarded from the script.

I fear it still is a bit buggy, since sometimes wrong counts appear in isolated lines of the logfile.
Maybe this is due to a failed NIC MIB query by lanadmin, which I so far didn't take any precautions to guard against.
But at least it doesn't seem to do any harm, and I have been running it now in daemon mode for a couple of weeks.

The script requires a decently current Perl version (e.g. >= 5.6).

If you made it executable and invoke it with the -h option you get a short help screen.

Would be nice if it is of any use to someone at all.


Madness, thy name is system administration
Stanimir
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

Hi!
I'm sending a full package for user/accounts
administration of 2-nodes cluster. It is
no need to use NIS or other sophisticated
service. This package is using client-server
technology to support identical accounts on
all nodes with replication.
Regards, Stan

Steven E. Protter
Exalted Contributor

Re: favorite sysadmin scripts you always keep around (3)

This is a script in need of one improvement, so its not a full 10 ponter for sure.

It clears shared memory areas based on a filter.

clearipc sag

clears all shared memory for user sag.

This user had memory leak or something in one of its apps and didn't release shared memory as its supposed to.

The ipcrm command is commented out on purpose.

Try it, check the output.

The problem with it is when the ID is long it gets confused about fields

s2121212121212 ad0x00000000 --rw-rw-rw sag sag

does not process right.

Its okay, but I think Bill might give you a rabbit for upgrading it.

The script is tested and works except as noted above.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Jean-Luc Oudart
Honored Contributor

Re: favorite sysadmin scripts you always keep around (3)

Bill,

this is to list users connected more than once from different IP @.

# dupuser : list of users connected on system more than once from
# different IP @

Rgds,
Jean-Luc
fiat lux
Tim Sanko
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

I have recently added to my morning routine a script called morning.sh on the production boxes. I got too lazy to do this by hand.

It is simple and has the following characteristics:

It runs a group of scripts and puts the output to /tmp/morning.txt

running uptime eliminates questions about when was this last rebooted

Keeping daily track of the ERP package
It is started with date > /tmp/mornin.txt
and terminates with date >> /tmp/mornin.txt
Clearing and dating morning activity.

I also keep track of admin activity.
What did you do yesterday???




Stanimir
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

Hi!
Here is an Perl-programs, which are
client-server application, worked as
socket. In addition the server is made to
work as daemon on one system.The client
have to work on another mashine and connect
to server for doing some useful job.
I thing, this is a good template for
developing many system applicatins -
monitoring, replication of data
and so on.

Regards,Stan
Stanimir
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

This is an addition of my previous
offer. The second script - the "client".
Clara Rowe
Frequent Advisor

Re: favorite sysadmin scripts you always keep around (3)

Sorry, I'm having trouble with the attachment. It's short:

#!/bin/sh
# A recursive grep.

while [ $# != 2 ]
do
if [ $# != 2 ]
then
echo "\nUsage:\trecurs \n"
echo "Insufficient number of paramaters (errno 69)\n"
fi
exit 1
done
while [ $# = 2 ]
do
echo "Please hold while I check that directory...."
cd $2
find . -depth -type f -follow -exec fgrep -l -i "$1" {} \;
exit 0
done
Take time to smell the roses.
jerry1
Super Advisor

Re: favorite sysadmin scripts you always keep around (3)

trashit script to get rid of several unwanted
emails in mail queue. Uses unique strings of from/to address when looking at queue using
mailq.

#!/bin/ksh
#set -x
#
# Trash junk email thats going nowhere.
# Jerry Moore 9/5/2001
#

PATH=/bin:/usr/sbin:.

DIR=/var/spool/mqueue
TFILE=/tmp/trash.file

>$TFILE

if [ ! "$1" ] ; then
echo ""
echo "Usage: trashit "
exit 1
fi

for i in `ls $DIR/ | grep -v ^df | sort -u` ;do
grep $1 $DIR/$i >/dev/null 2>&1
if [ "$?" = "0" ];then
ls $DIR/$i >>$TFILE
fi
done

if [ -s $TFILE ] ; then
for i in `cat $TFILE`;do
echo "Removing qf file $i
rm $i
echo "Removing df file `echo $i | sed s/qf/df/`."
echo $i | sed s/qf/df/ | xargs rm
echo "Removing any xf files."
echo $i | sed s/qf/xf/ | xargs rm
done
else
echo "No control files match string ( $1 )"
fi

/bin/rm -f $TFILE

#END
Donny Jekels
Respected Contributor

Re: favorite sysadmin scripts you always keep around (3)

here's another script to mirror your ignited box automatically.

it tests for the alternate path, minimal size, etc.

works on any 9000/700 or 9000/800 platform. I am busy extending the capability to work on Itanium hardware. only LVM at this time.
"Vision, is the art of seeing the invisible"
Doug Burton
Respected Contributor

Re: favorite sysadmin scripts you always keep around (3)

OK... That didn't work to well so I'll put it here and add the attachement (again):

#!/bin/ksh

# Run netstat to get "FIN_WAIT_2" info.
# We then keeelllll them for fun.

stuff=$(/usr/bin/printf "%.2x%.2x%.2x%.2x%.4x%.2x%.2x%.2x%.2x%.4x\n" \
$(/usr/bin/netstat -an -f inet | /usr/bin/grep FIN_WAIT_2 | \
/usr/bin/awk '{print $4,$5}' | /usr/bin/sed 's/\./ /g'))

for x in $stuff
do
/usr/bin/ndd -set /dev/tcp tcp_discon_by_addr $x
done
Jan Zalman
Advisor

Re: favorite sysadmin scripts you always keep around (3)

Hi all, a short way to beautify your path. Regards.
Time and loyalty cannot be bought.
Steven E. Protter
Exalted Contributor

Re: favorite sysadmin scripts you always keep around (3)

Tested.

Wonderful.

Based on /etc/fstab

The Defragmentation Script.

Online JFS required.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Robert Binkhorst
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

Hi,

I'm not the originator for this script (Jan Verbakel is) but I did enhance it a bit.

Features:
# - Use a list of servernames to do more than 1 server at a time.
# - Have the script generate a list of servers with a specific release number.
# - Generate verbose output for easing reading/checking or
# Non-verbose output for use in spreadsheets.
# - Run a single command or a script full of commands on multiple servers.
# When running a script output is stored on the originating machine.
# No files are left on the remote servers, unless your script does so.

It uses the rtools series, so it's still useful for those of us without ssh everywhere!

Cheers,

Robert
linux: the choice of a GNU generation
Alan Turner
Regular Advisor

Re: favorite sysadmin scripts you always keep around (3)

attach didn't work - pasting

#!/bin/sh

SLOT=1
DEV=c4t0d0

BLK=/dev/dsk/${DEV}
RAW=/dev/rdsk/${DEV}

echo "This script recovers a system when the disk in slot 1 has failed."
echo "Slot 1 is at the bottom (LHS viewed from front at XXX) and shows"
echo "up in ioscan as $RAW, and in lvdisplay as $BLK"
echo "Check which drive is marked as 'stale' using lvdisplay, e.g."
echo " lvdisplay -v /dev/vg00/lvol | grep stale ( = 1 .. 9)"
echo ""
echo "Are the stale extents on $DEV ? (y/n) \c"
read resp

case "$resp" in

[yY]* )
echo ""
;;
* )
echo "Abandoning"
exit 0
;;
esac

echo "Doing an ioscan now, to check the state of the disk..."
ioscan -fnCdisk

echo "The disk $RAW MAY show up in error, e.g. NO_HW"

echo "If you want to continue, remove the failed disk and press return"
echo "(Note, you must have another module ready, don't put it in yet, but"
echo "be ready to put it in within 5 minutes.)"
echo ""
echo "Press return when disk is out ...\c"
read resp
echo "Doing another ioscan so HPUX realises the disk has gone"
ioscan -fnCdisk
echo "OK, we really do expect $RAW to show up as NO_HW this time,"
echo "definitely not to show up as CLAIMED"
echo "If it is CLAIMED, it looks like you've removed the wrong disk."
echo ""
echo "Assuming all is well, put the replacement disk into the slot $SLOT"
echo "then press return ...\c"
read resp
echo "Doing another ioscan so HPUX realises the disk has changed."
echo "We now expect the disk to show up as CLAIMED."

ioscan -fnCdisk

echo "Did the disk $RAW show up as CLAIMED ? (y/n) \c"
read resp

case "$resp" in

[yY]* )
echo ""
;;
* )
echo "Abandoning"
exit 0
;;
esac

echo "OK, will start initialising the disk in 5 seconds (CTRL-C to stop)"
echo "5 \c"
sleep 1
echo "4 \c"
sleep 1
echo "3 \c"
sleep 1
echo "2 \c"
sleep 1
echo "1 \c"
sleep 1
echo "0"
echo "running vgcfgrestore"
vgcfgrestore -n /dev/vg00 $RAW
echo "vgchange"
vgchange -a y /dev/vg00
echo "vgsync - this should take several minutes, especially for lvol4 and lvol5"
vgsync /dev/vg00

echo "running mkboot"
mkboot -l $RAW
mkboot -a "hpux -lq (;0)/stand/vmunix" $RAW

echo "Running lvlnboot, though not sure its needed"
lvlnboot -r /dev/vg00/lvol3 /dev/vg00
lvlnboot -b /dev/vg00/lvol1 /dev/vg00
lvlnboot -s /dev/vg00/lvol2 /dev/vg00
lvlnboot -d /dev/vg00/lvol2 /dev/vg00

echo "Putting ODE onto the boot area"
mkboot -b /usr/sbin/diag/lif/updatediaglif \
-p ISL -p AUTO -p HPUX -p PAD -p LABEL $RAW
echo ""
echo "Done."
exit 0
Ernesto Cappello
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

#!/usr/contrib/bin/perl
# Show the percentage of total used space in /users to each user
# 11/18/02 BRS

$user_thresh = 1 ;

# Get the size of each users home directory

# sub users_report {
$user_total = `du -sk /users 2> \/dev\/null`;
($user_total,$nothing) = split(/\s+/,$user_total) ;


print "/users's total usage is $user_total kb \n" ;

foreach (`du -sk /users/* 2> \/dev\/null` ) {
chop ;
($user_kb,$user_dir) = split (/\s+/);
$users_size{$user_dir} = $user_kb ;
$user_pct = int(($user_kb / $user_total) * 100) ;
if ( $user_pct > $user_thresh ) {
print "$user_dir ($user_kb kb) is $user_pct% \n" ;
}
}


Regards, Ernesto.
Ernesto Cappello
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

This script for bdf on unix server

#!/bin/sh
THRESHHOLD="7[0-9]%"
THRESHHOLD1="8[0-9]%"
THRESHHOLD2="9[0-9]%"
THRESHHOLD3="100%"
# BDF ON PIPPO_SERVER
echo "####################" > bdf_on_servers.txt
echo "# BDF ON PIPPO_SERVER #" >> bdf_on_servers.txt
echo "####################" >> bdf_on_servers.txt
echo "\n" >> bdf_on_servers.txt
echo "Filesystem kbytes used avail %used Mounted on \n" >> bdf_on_servers.txt
bdf -l | grep -e $THRESHHOLD -e $THRESHHOLD1 -e $THRESHHOLD2 -e $THRESHHOLD3 >> bdf_on_servers.txt
ux2dos bdf_on_servers.txt | mailx -s "BDF on UNIX SERVERS" pippo@ops.test.it
Andrew Penney
Advisor

Re: favorite sysadmin scripts you always keep around (3)

Here's a little piece of code I put together, or found somewhere, to re-nice run-away processes so my root logon will have a higher priority.


#!/usr/bin/sh

for arg in `ps -fel |grep sas |grep -v grep|cut -c 15-21`
do
# echo "renicing" ${arg}
renice -n +19 ${arg}
done

I run it with a cron every five minutes:
1,6,11,16,21,26,31,36,41,46,51,55 * * * * /root/scripts/sasfix.sh >/tmp/trace1 2>&1

I'm trying to make a script to check and see if users have more that on process running and then kill off the older processes. Can anyone help?

Thanks
sam_111
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

hi,

Here are some links to very good scripts

http://www-


http://www.intuitive.com/wicked/wicked-cool-shell-script-library.shtml

106.ibm.com/developerworks/linux/library/l-punix?open&l=765,t=grl,p=punix

Good Book on Shell Scripting

http://www.intuitive.com/wicked/table-of-contents.shtml


regards,

sam
"Hard Work always Pays off"
Jdamian
Respected Contributor

Re: favorite sysadmin scripts you always keep around (3)

Here you have an ksh or sh-posix alias to convert a string into a C-style string (tab -> \t, new line -> \n,... see vis(1) command manual pages).

# cstring
alias cstring='( ( vis -n; print ) | while read -r X; do Y="${Y}${X}"; done; print -r "${Y%\\n}" )'

# echo ' t \na' | cstring
\st\s\na
Ng Tommy
New Member

Re: favorite sysadmin scripts you always keep around (3)

Hi Bill,

Just got to know of this thread 2 days ago, great stuff. Attached is a small script to monitor syslog.log for keyword for preactive/preventive alert. This is a live production script. To keep log fresh, it perform log rotation after 3 alerts and call /dev/null to zero the syslog.log - not sure this is right approach but it work for us. After the log refresh, it went to sleep for 1 hr. BTW, this script MUST run in root and in backgroud.

Usage: # /usr/bin/sh /usr/local/bin/syslog_mon.sh &
Radhakrishnan Venkatara
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

Script will just list the disk that are in LVM and disk that are not used in LVM.

#!/usr/bin/sh
strings /etc/lvmtab | grep -v vg | grep -v "^$" | cut -d "/" -f4 >/tmp/use.out
# Below line will create list of cxtxdx
ioscan -funC disk | awk '{ if ($3 != "") printf ("%s",$0) ; else printf ("%s\n",$0)}' | grep -v DVD-ROM | grep -v Class | awk -F "/dev" '{p
rint $2}' | awk -F "/" '{print $3}' > /tmp/disk.lst
#Below line will create list of lun numbers d# But not used in this Script
ioscan -funC disk | awk '{ if ($3 != "") printf ("%s",$0) ; else printf ("%s\n",$0)}' | grep -v DVD-ROM | grep -v Class | awk -F "/" '{prin
t $7}' | cut -d "d" -f2 > /tmp/d.lst
clear
echo "\t SL.No \t DEVICE FILE \t DISK TYPE \t\t DISK SIZE IN GB \t DISK STATUS "
echo "\t ----- \t ----------- \t --------- \t\t --------------- \t -----------\n\n"
N=0
for i in `cat /tmp/disk.lst`
do
#for j in `cat /tmp/use.out`
#do
if [ `/usr/sbin/diskinfo /dev/rdsk/$i | grep size | awk '{ print $2 }'` -gt 50000 ]
then
grep $i /tmp/use.out 1> /dev/null
if [ "$?" != 0 ]
then STAT=" Unused "
else STAT=" Used "
fi

{ ((N=N+1))
if [ `echo $i | cut -d "d" -f2` -ne 0 ]
then
SIZE1=`/usr/sbin/diskinfo /dev/rdsk/$i | grep size | awk '{ print $2 / 1048576 }'`
echo "\t $N \t $i \t Array of disks [LUN=`echo $i | cut -d "d" -f2`] \t $SIZE1 \t $STAT "
else
SIZE=`/usr/sbin/diskinfo /dev/rdsk/$i | grep size | awk '{ print $2 / 1048576 }'`
echo "\t $N \t $i \t normal disk \t\t\t $SIZE \t $STAT "
fi
}
fi
done
echo " \n\n\t Note: Disk Status indicates use of Disk in LVM configuration only. \n\n"
Negative thinking is a highest form of Intelligence
Fred Ruffet
Honored Contributor

Re: favorite sysadmin scripts you always keep around (3)

Here is a small perl script that produces a parseable output for bdf (no dual lines, fields separated by ":").

Output sample :
> ./bdf2
/dev/vg00/lvol1:298928:84392:184640:31%:/stand
/dev/vg00/lvol3:311296:278960:32120:90%:/
/dev/vg00/lvol4:4194304:2025800:2151600:48%:/opt
/dev/vg00/lvol5:524288:403808:120096:77%:/tmp
/dev/vg00/lvol6:1785856:1242328:539288:70%:/usr
/dev/vg00/lvol7:4194304:1056976:3113096:25%:/var
/dev/vg00/lvol8:262144:2344:257776:1%:/home


Fred
--

"Reality is just a point of view." (P. K. D.)
Kent Ostby
Honored Contributor

Re: favorite sysadmin scripts you always keep around (3)

These are more command line things I use a lot:

1) Which processes have racked up a lot of CPU.

ps -ef | cut -c42-80 | sort -nr | head

2) A "pipe to" thing to remove a list of files that I found some way:

| awk '{print "rm -r ",$NF,}' > useme

So I might use this for instance in cleaning up all the files that were created before April or May.

ll | grep -v -e Apr -e May | awk '{print "rm -r ",$NF,}' > useme

The file "useme" now contains a bunch of statements like:

rm -r Exaaaaae0123 (or whatever types of files they seem to be).

So then I:
chmod +x useme; ./useme

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Roberto Polli
Trusted Contributor

Re: favorite sysadmin scripts you always keep around (3)

Search and substitute a string on multiple file if use in conjuction with rsh


echo -e ":%s/STRING/SUBST/\\n:wq\\n"|vi FILENAME


Peace, R.