Operating System - HP-UX
1844311 Members
2803 Online
110230 Solutions
New Discussion

favorite sysadmin scripts you always keep around (3)

 
SOLVED
Go to solution
Chris Vail
Honored Contributor

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

Attached is one of my more involved scripts, diskasaurus. This is specifically for EMC Symmetrix users, but could be adapted as you see fit. It takes the output of BDF and provides additional interesting information. It determines if the disk is local or remote, whether and/or how it is mirrored. If the disk is striped, it determines whether it is a 4-way or 8-way stripe. Finally, it accumulates the data into .csv format for easy use with Excel or other spreadsheet. I email the results to myself for analysis. You will need the EMC command "inq" available to generate the base information.

It has a parent script, T-REX, that I'll attach if anyone is interested. This script uses secure copy to deploy diskasaurus to machines listed in a text file. It then executes it and captures its output into a larger .csv file, and does some interesting subtotals and totals of the data. The first script runs by itself nicely, but with T-REX it becomes a powerful tool to analyze multiple systems simoultaneously.
Steven E. Protter
Exalted Contributor

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

Tired of two line commands to start and stop daemons?

Well suffer no longer.

restart

Let me know if the name causes problems, it is tested.

usage:

restart

It requires root $LOGNAME
It requires a single parameter

It saves me typing.

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
Massimo Bianchi
Honored Contributor

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

Hi, a little query in oracle:


select p.spid from v$process p, v$session s, v$mystat m
where m.sid=s.sid and s.paddr=p.addr and rownum=1;



This is used to extract the pid of the session you are connected to.
Usefull because when you generate a user_trace (like in alter database backup controlfile to trace) the output goes to user_dump_dest/ora_.trc , format depending on otacle release.

I always hate to list the content and look for my file, guessing...

Massimo
Steven E. Protter
Exalted Contributor

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

This beauty is for those Linux-heads who have stepped up to the world of real Unix. HP-UX.

In Linux you can stop, start and restart services with a single command.

service

service httpd restart

restarts the httpd daemon(web server)

Its nice.

As far as I know, no equivalent exists in HP-UX.

Until now.

It works just the same, taking three valid actions. It may be a bit verbose, but you can play with it to your hearts content.

attaching service.

This has been tested in all three valid modes.

If the script does not exist in /sbin/init.d/ it tells you.

WARNING: This script will not protect you from your own stupidity. If you use it to halt a critical service like NFS or the network, your system will lock up good and hard. Use at your own risk. Example: This script did not protect me from my own stupidity when I let it loose on Samba while a file transfer was going on. It is not smart enough to know if its a good idea to start/stop or restart the service, it relies on you for that part.

WARNING 2: There are probably some services that can't be stopped and started while the system is running. Once again, this script is only as smart as the person using. It does however ease the transition from Linux to HP-UX.

I'm thinking about doing chkcfg(chkconfig?) next. It actually sets up servcies to run which makes it a little harder to port.

Enjoy.

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
Steven E. Protter
Exalted Contributor

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

I'm pretty sure this doesn't deserve any points.

Reason is I promised this pup months ago.

Its a really minor modification of a slick script given to me by Jordon Bean in response to an itrc post to port my Linux buildmail script.

What this script does is it builds the sendmail databases for alisees, access (spam stopper), and such things so you can use your HP-UX box to run an NSP.

I don't know how many people actually do that, but I'm in a jam right now.

My production Linux Server is running 7.3 Red Hat. It is having hardware problems. It only booted correctly six out of the last seven times. It hung on the memory check a few hours ago, after I loused up the named database.

A few weeks ago, its built in video card took a dump. The good news is it came back and the server wasn't down for more than 10 minutes.

What I need to do is take production offline, put in a reliable add in video card, put the two hard disks on different IDE channels and rebuild the box.

Normally I'd just switch to the backup Linux box. Its been upgraded to Red Hat 9 and none of my sendmail stuff works with sendmail 8.12.

So The old D320, my learning box may be pressed into a few days of service to save my tush.

DNS, httpd(apache 2 no less) works. sendmail has to work to give me the time I need to fix the Dell Linux box.

That was long winded. Here is the script. The script itself works. The sendmail functionaility it creates, databases and such is still being tested furious as I type.

Not surprisingly I was able to bring over all my virtusertable, genericstable, tab delimited databases without modification.

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
Zigor Buruaga
Esteemed Contributor

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

Hi,

Sometimes "who" shows users that are not logged on the system. I have attached a script that searches ghost users, and remove them.
Usually those users closed their X client application improperly.

Hope this helps somebody.
Kind regards,
Zigor
Zigor Buruaga
Esteemed Contributor

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

Hi,

One more, I usually use the attached script to find in a couple of seconds if a user is locked in the trusted system. If the user is locked due to max failed login attempts, or due to max inactivity time, then is automatically reactivated.

Hope this helps somebody.

Kind regards,
Zigor
Zigor Buruaga
Esteemed Contributor

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

Hi,

Attached a script that enable/disable passwd aging in trusted systems, only for those users whose home directory is "client". It can be adapted easily to meet other requirements.
We did this script because there are users excluded from using passwd.
Zeev Schultz
Honored Contributor

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

how to find all Suid/Sgid/Sticky bit?

find / -perm 4000 -o -perm 2000 -o -perm 1000

And can add any chmod masks one like (writable in /etc ... etc :) )

Zeev
So computers don't think yet. At least not chess computers. - Seymour Cray
Paulo A G Fessel
Trusted Contributor

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

This script will syncronize the archive logs from one server to another, creating logs of both successful and unsuccessful operations.

It's written in perl and is in production here right now. Just change the paths and you'll be able to it yourself.

[]'s
Paulo Fessel
L'employé propose, le boss dispose.
Tim Sanko
Trusted Contributor

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

This finds largest files and tails out the 15 largest. My manger can use it...

du -ak $1 | sort -n > /tmp/dulist
tail -15 /tmp/dulist

Tim
Mark Greene_1
Honored Contributor

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

Find out the hardware info for all your disks:

#!/bin/ksh

for i in `ioscan -fnC disk |grep rdsk | awk '{ print $2 }'`
do
diskinfo -v $i
done

It's useful to have a hardcopy or at least the results redirected to a file. That way if you lose a disk and call for a replacement, you have the all important Product ID on hand.

mark
the future will be a lot like now, only later
Hein van den Heuvel
Honored Contributor

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



Tim Sanko wrote:
> This finds largest files and tails out the 15 largest.
> My manger can use it...

> du -ak $1 | sort -n > /tmp/dulist
>tail -15 /tmp/dulist

I'd suggest telling the system to just find the interesting files before sorting.

Perhaps something like:
find $1 -size +10000000c -exec du -k {} \;| sort -n | tail -5

fwiw,
Hein.

Tim
Randy Tarrier
Advisor

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

I use this to update label name and location on Data Protector cartridges. You supply the backup name, it modifies those fields on the latest session. You can set it to run as post-exec..
Do it as long as you love it!
Rodney Hills
Honored Contributor

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

This script I call "mountcd" helps me by reminding me if I already have a cd mounted.

I can type-
mountcd /cdrom (to mount cd on /cdrom)
mountcd (to tell me if a cd is mounted and where)


#!/usr/bin/sh
cd=/dev/dsk/c4t3d0
arg1=$1
set -A ary `grep "^$cd" /etc/mnttab`
arg2=${ary[1]}
if [[ "x$arg2" = "x" ]] ; then
if [[ "x$arg1" = "x" ]] ; then
echo "Syntax : mountcd /MOUNT_POINT"
else
if [[ -d $arg1 ]] ; then
mount -r $cd $arg1
else
echo "$1 is not a DIRECTORY"
fi
fi
else
if [[ "x$arg1" = "x" ]] ; then
echo "CDROM mounted at $arg2"
else
echo "CDROM already mounted at $arg2"
fi
fi
There be dragons...
John Stiles
Frequent Advisor

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

Bill,

attached is a script i use for file management.

John
all things must pass
Tim Sanko
Trusted Contributor

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

Hein,

I also have to explain it to my manager who thinks he is "hands on". I have tried to explain "find / -name \*.sar -exec gzip {} \;"
to her for enough time to avoid find forever.

I also have had to explain the syntax for awk (feel the shudder)...


Sometimes simple is better, but not always...

Tim
Mark Grant
Honored Contributor

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

This is odd, ugly and been sitting around inused for a while but it is odd enough to be useful for some people. It checks through the last set of Omniback backup schedules looking for gaps when a tape device was idle. It shows periods of time (in fifteen minute chunks) when each tape drive was not being used. This is useful for making scheduling decisions.
Never preceed any demonstration with anything more predictive than "watch this"
Khalid A. Al-Tayaran
Valued Contributor

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


Hi all,

Not a script really but continuing from Tom Sanko and Hein Van Den Heuvel:

To find n largest files, example (largest 20):

largestFiles /oracle 20

Here's the technique:
find $1 -size +10000000c -exec du -k {} \;| sort -n | tail -$2 | more

It worked for me....
Mark Grant
Honored Contributor

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

Filesystem usage checker on a per filesystem basis.

This script allows you to specify warning and critical thresholds for individial filesystem, groups of filesystems (identified with regular expressions) and even filesystems on a range of machines. It can alert to openview, it can keep a database which allows for specifying thresholds and re-arm values. It has the code (commented out) for doing the job across a range of different machines. If checking several machines, those machines can be either HP-UX, Solaris, AIX or Linux or a mixture of them.

You'll need to create a config file but an example is in the comments of the script.

Mail me if it needs tweaks for your environment.
Never preceed any demonstration with anything more predictive than "watch this"
Holger Knoppik
Valued Contributor

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

Hi there !

below is one of my weekly cron jobs for backup.
NOTE: Only the hostnames are not original. The script is used in a 4 server environment where 2 servers are used as ignite servers.

regards, Holger
Live long and prosper!
Steven E. Protter
Exalted Contributor

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

While off in Wyoming, a disk failed on my D380/2 server and mhy previously contributed script checkhardware.sh totally missed it.

Apparently it went from lively to death in less than the 24 hour window between check runs.

So I needed something that could spot a problem if a drive dies without an lbolt.

The idea came to mind to use strings /etc/lvmtab as a database. Then run a pvdisplay and if the error code returns 0 the disk must be okay. If non-zero, email me FAST.

So I wrote this script.

This script is tested, so I think it qualifies for points. I tested it against an invalid copy of lvmtab and it did indeed email me saying a disk was down. The nice part was that it included the /dev/dsk/c###### info on the email subject line.

Anyway, here it is. It actually emails a bunch of people, but I cut those out for privacy concerns. Everyone here knows my email addy anyway.

disk.status.....

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
Donny Jekels
Respected Contributor

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

I wrote this perl script to mimic a "tail -f /var/adm/syslog/syslog.log" and it runs as a daemon.

It searches for key words and email the unix admins and or a pager.

It use the module File::Tail

It is not inteligent enough, to sense when you switch the log file (yet), so remember to stop and start the daemon when you rotate the logs.

peace
Donny
"Vision, is the art of seeing the invisible"
James Specht
Trusted Contributor

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

Here is a script I wrote for Data Protector. We backup important workstations, but some of them have been replaced with laptops that sometimes leave our network at night. This script looks for the laptops that are still on the network and adds them to the backup.

Example support files included.
"Everyone can be taught to sculpt: Michelangelo would have had to be taught how not to. So it is with the great programmers."
James Specht
Trusted Contributor

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

Here's a quick ditty for getting information on the core files you find on your system.

find / -name core -type f -exec echo "\n" \; -exec file {} \; -exec what {} \;
"Everyone can be taught to sculpt: Michelangelo would have had to be taught how not to. So it is with the great programmers."