Operating System - HP-UX
1844817 Members
2271 Online
110233 Solutions
New Discussion

favorite sysadmin scripts you always keep around (3)

 
SOLVED
Go to solution
edwin hamers
Advisor

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

Hi,

I want to share my backup/verify tool called Miniback.
Yes, i stole the name from Omniback, but since it is quite small, hence miniback.
Anyway, this is what it does.

It uses the fbackup/frecover combo to make a backup, and this backup is checked by restoring a file with frecover.

A short manual is supplied.

Since we use HP Openview, it reports errors through HPOV. If you dont like that, then you can switch it off.

I attached this as a depot file.
It will install the scripts into /var/adm/fbackupfiles.
IT WILL OVERWRITE FILES THERE...

Be warned

Have fun





Chant and be happy
Borislav Perkov
Respected Contributor

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

Hi,
Here is a version of one of the bdf extension script, where there is filesystems with longname. Here inodes are included in the script.

Regards,
Borislav
Petr Simik_1
Valued Contributor

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

By this simple script you can run any command on multiple remote servers. I use it to check, setup or download informations from platforms.
Setup of this script is to create rrun.conf file and put there the list of needed servers. It uses .rhosts trusting.
Script I attached is written by somebody else from ITRC I downloaded it long time ago and since now it is ome of my favourites.

Arturo Galbiati
Esteemed Contributor

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

Hi,
some one-line commands usefull to administarte Oracle mount points:

# Show oracle disk with pct used >= PCT
bdf|awk -v PCT=30 'NR==1||(substr($5,1,index($5,"%")-1)+0>=PCT&&/oracle/)'

# Show Oracle disk with available space >= AVL (1Mb)
bdf|awk -v AVL=1048576 'NR==1||($4>=AVL&&/oracle/)'

Art
Zinky
Honored Contributor

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

To folks who use VxVM Extensively, here's a script that displays all Diskgroups, volumes, their sizes and if they're mounted and where. I also have it as an attachment.

Am sure a Perl Wiz should be able to re-write this and make it faster/more efficient but it does work for me:


#!/bin/ksh
#
# dginfo
# Show a server's VxVM Configuration and Layout
#

echo "DGINFO - VxVM Summator v 1.0 Dec. 2005"
echo "VxVM - All Versions"
echo "AITS Unix"
DGLIST=`vxdg list|awk '{print $1}'|grep -v "NAME"`
echo
echo "VxVM Summary for Server `hostname` @ `date`"
echo
for DG in $DGLIST;do

# Get Total Allocations
SIZE=`vxprint -ht -g $DG|grep ^dm|awk '{s+=$6}END{printf "%8.2f",s/1024/1024}'`
FREE=`vxdg -g $DG free|grep -v DISK|awk '{s+=$5}END{printf "%8.2f",s/1024/1024}'`
printf "DG: %-20s Capacity: %7.2f GB Free: %7.2f GB\n" $DG $SIZE $FREE
echo "=========================================================================="
vxprint -ht -g $DG|grep ^v|grep -v dcl|awk '{print $2,$6}'|while read vol size;do
fs=`mount -p|grep -w /dev/vx/dsk/$DG/$vol|awk '{print $2}'`
printf "VOL: %-20s %10d GB. %30s\n" $vol $((size/1024/1024)) $fs
done
printf "\n"
done

Hakuna Matata

Favourite Toy:
AMD Athlon II X6 1090T 6-core, 16GB RAM, 12TB ZFS RAIDZ-2 Storage. Linux Centos 5.6 running KVM Hypervisor. Virtual Machines: Ubuntu, Mint, Solaris 10, Windows 7 Professional, Windows XP Pro, Windows Server 2008R2, DOS 6.22, OpenFiler
Coolmar
Esteemed Contributor

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

I wrote this script for all those times that I had to kill a bunch of processes owned by the same user, or same name. For example, you stop oracle but there are still a bunch of processes hanging around. My script requires input - the owner of the process and the process name (ie ora*)

#! /usr/bin/ksh

# This script will kill any processes that are running. Good if there are a bunch of them, like Java or http.
# You must supply the process and the userid when running the script

echo "Process Name? \c"
read ans

echo "Userid? \c"
read user

ps -ef |grep $ans | grep $user |grep -v grep |awk '{print $2}' |while read PID
do
kill -9 $PID
done
Jan van den Ende
Honored Contributor

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

Hi,

For those who like this same idea on VMS, the OPENVMS.ORG people created a separate site:

http://dcl.openvms.org/

Well worth a visit, lots of interesting stuff there! (even some of mine).

Happy New year (carefull with the fireworks, they DO make nice glass eyes, but they still have inferior vision!).

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Pete Randall
Outstanding Contributor

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

Not having heard from our good friend, Bill in quite some time, I have to wonder what he's up to nowdays.

Anyway, a couple of comments on Sally's "kill script" contribution:

First, simply grepping a user name or command can be dangerous. There is always the possibility that an inadvertent match may end up killing something that you didn't really want to kill. A far better alternative is to use the XPG4 functionality of the ps command like this -
PROCESSES=`UNIX95= ps -U $USERNAME | grep -v PID |awk '{ print $1 }'
A similar technique is, I believe, available for the command, using the XPG4 option "-C".

Secondly, doing an arbitrary "kill -9" gives the process no chance to clean up after itself, leaving shared memory segments, etc, still occupied. At the very least, a plain
kill, which defaults to SIGTERM, or kill -15, should be tried before resorting to kill -9. Something like this -
kill $PROCESS
sleep 2
kill -9 $PROCESS

Just a couple of suggestions.


Pete

Pete
Bill Hassell
Honored Contributor

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

Pete beat me to it...I strongly discourage using grep+ps for ANY automated script. As Pete said, grep is indiscriminate. It knows nothing about usernames or process names, so a match on something else, while accidental, can have very serious effects (ie, kill -9). ps has a *LOT* os unused options that eliminate the need for grep, and most important, ps does exact matches by field. So if you want a specific user, always ask ps to find the user as in:

ps -f -u user_name

Similarly, to find a process, always use -C process_name and you won't get any mistakes. Check the difference between these two commands:

ps -ef|grep sh

UNIX95=1 ps -f -C sh

You'll see not only sh shell processes, but possibly ksh, csh, bash, and most important: unhasdaemon. You NEVER want to kill unhasdaemon.

Now there are 3 really useful options that are non-standard with ps: -C -H and -o. Check the man page for the details. But these options only wirk when the (normally undefined) variable UNIX95 exists. Don't be tempted to set UNIX95 permanemntly as this variable can affect other processes and libraries. Put it on the same line as ps.


Bill Hassell, sysadmin
Steven E. Protter
Exalted Contributor

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

UNIX95's most nasty impact is on checksums when you try and sh a depot or other download from HP.


I did produce a safe version of the kill script that was never allowed to touch a process owned by room. Those are best killed manually.

I've been converting my grep kill script to the new, safer Bill Hassell method.

I've been thinking of creating a searchable database of all these scripts based on keywords.

Perhaps maintain the database of characteristics in a sql database. I'd need a we bit of help getting that done. Interesting concept, great script database, sometimes hard to find it where it sits now.

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
Bill Hassell
Honored Contributor

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

Sorting the processes by memory usage is easy with ps:

UNIX95=1 ps -e -o vsz,pid,ruser,args | sort -rn

To log this as a 1-liner, change the line to:

UNIX95=1 ps -e -o vsz,pid,ruser,args | sort -n | tail -1

This will put the biggest (local memory) process at the end of the list. That said, memory usage by a process is a lot more complicated than just local memory. A set of processes may share an enormous segment of memory but that is by design. Similarly, a process may need a lot of local memory to run correctly. Large memory usage is not a bad thing if the program is running correctly. HP-UX is a virtual memory system and will deactivate and page out low priority programs when RAM is fully used.


Bill Hassell, sysadmin
rmueller58
Valued Contributor

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

I use this to check top user processes and exclude root and informix.. I use it specifically when my system seems to be getting beat up.. We've isolated a couple buggy vendor apps doing this.

ps -ef |grep -v informix|grep -v root |grep -v lp|awk '{print $4, $1, $2, $7, $8, $9, $10, $11, $12,$13, $14, $15}' |sort -r| head -10

Doug O'Leary
Honored Contributor

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

Hey;

id_mirror: IDs which lvs in vg00 are mirrored and which aren't...


------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Doug O'Leary
Honored Contributor

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

id_lv_disks: Scans all the disks on a system and ids which ones belong to vgs, which ones don't and which ones should belong to vgs but don't.

Primarily used to identify pvlinked disks thata aren't part of a vg.

Unfortunately, this one needs a little work. Biggest issue is identifying the cdrom/dvdrom or any of the other names by which it goes on the various systems. (line 67). Once that's done, it works pretty well, at least on the systems that I've run it on...

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Doug O'Leary
Honored Contributor

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

verify_nic: Prints information about each configured network card: interface, IP, auto-negiotate, and speed.

Useful for scanning multiple hosts simultaneously if you have ssh pka and gsh configured...


------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
TKeller
Frequent Advisor

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

Attached is a perl script I was asked to write for some developers who wanted an daily mailer set up for several excel spreadsheets they wanted to send out. It's a multi-tiered progression line as you'll see below.

1. On main developer's WinXP machine, set up
a scheduled task to run send_files.bat which is nothing more than a automated ftp using 'ftp -s:send_files.txt' which connects to the unix machine as a generic ftp user to dump the excel files.

2. Cron job on unix box runs daily with the attached script to prep the files for emailing. The excel files on the WinXP box always stay the same whereas the script will use perl to munch on the name of the new files on the unix box.

Example: WinXP sends over the file 'one.xls'. Perl script makes that turn into 'one06092006.xls' before it gets sent out.

Safeguards:
- any argument will show a debug mode checking to see if excel files already renamed exists and ignores them
- doesn't do anything if 0 files exist
- directory and path traversal stuff
- strict mode enabled, of course
- entirely perl, no system or exec calls

And there it is, hehe...it's in production.
It is said you should treat your body like a temple. I treat mine like an amusement park.
Jim Purtell
Frequent Advisor

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

Something as simple as this is easily forgotten. Handy one-liner for date manipulation.


Todays date
$ export _dt=$(date "+%m")$(date "+%d"|bc)$(date "+%y")
$ echo $_dt
09806

Yesterdays date
$ export _dt=$(date "+%m")$(date "+%d - 1"|bc)$(date "+%y")
$ echo $_dt
09706


It's all in the 'bc'. Hope this is as handy for others as it has been for me.

Jim
A. Clay Stephenson
Acclaimed Contributor

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

There are a few logic holes in the previous post:

Yesterdays date
$ export _dt=$(date "+%m")$(date "+%d - 1"|bc)$(date "+%y")
$ echo $_dt
09706

1) Not too serious because it is not very probable:
$ export _dt=$(date "+%m")$(date "+%d - 1"|bc)$(date "+%y")

Invoking date 3 separate times could result in an invalid date because this could occur at midnite so that the month, day, and/or year might not agree. A single call to fewtch all three in one shot is much better.

2) Serious and quite likely to occur:
Consider what happens when this script is run on the first day of any month. I'm not aware of too many calendars that allow a day 0 (although the math would be easier if calendars were zero-based).
If it ain't broke, I can fix that.
Jim Purtell
Frequent Advisor

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

It's just a one-liner (like I said) that I thought I'd pass along. It's up to you how you use it.

I've incorporated it into a few things without any problems. And haven't seen anyone else find yesterdays date with such little effort.

PS: please, no points for ether post - it's just a small contribution

Thanks,
Jim
charles butkus
Advisor

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

I wrote this over a few days... my first C program.

It sleeps for 100ths of a second, accurate to within .03 seconds (usually over).. I believe that it's due to the way the system schedules processes to run.. it's .01 accurate if I run it in rtprio.

I like it for when I'm dumping a stream of commands into a telnet ( telnet SERVERNAME < $(echo ls; sleep 1; echo bdf) )..

I noticed that HP had provided a nanosleep function in time.h, but nobody had taken advantage of it, and a few people had asked for one on the ITRC.

In reality, it's not very usefull outside of starting to learn C...

charles butkus
Advisor

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

And here's the compiled version for those without ANSI C..
mobidyc
Trusted Contributor

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

Hello,

it's time for revival of this thread.

this script is adapted from a script found here (i don't remeber who) and contains ameliorations.

the output is like that:
#> bdfa /var
File System Mbytes Used Avail %Used Inods Free %Used Type Mounted on
/dev/vg00/lvol7 6144 1669 4440 27% 35211 143189 20% vxfs /var
Best regards, Cedrick Gaillard
mobidyc
Trusted Contributor

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

Hello,

there is an alias you can insert in the /etc/profile in replacement of the 'bdf' command...without the ugly line return.

this alias is attached because there are tabulations in, old sed versions don't know of the \t char.
Best regards, Cedrick Gaillard
mobidyc
Trusted Contributor

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

Hello,

under solaris, you have ptree for listing process, there is a small equivalent for HP-UX.

you can launch with the following args:
ptree 0
for a complete listing

or the following example:
# ptree 6913
+++++ root 1 0 0 Mar 22 ? 11:37 init
++++ root 1025 1 0 Mar 22 ? 0:40 /opt/ssh/sbin/sshd
+++ root 29222 1025 0 12:47:52 ? 0:00 sshd: root@pts/0
++ root 29227 29222 0 12:47:54 pts/0 0:00 -ksh
+ root 29497 29227 0 12:47:57 pts/0 0:00 bash
0 root 6913 29497 0 17:08:51 pts/0 0:00 ksh
- root 6917 6913 0 17:08:52 pts/0 0:00 bash
-- root 7123 6917 0 17:08:54 pts/0 0:00 ksh
--- root 8527 7123 1 17:09:35 pts/0 0:00 /bin/ksh /outil/adm/bin/ptree 6913
---- root 8530 8527 1 17:09:35 pts/0 0:00 ps -ef

i've launched multiples shells specially for this example ;)

Regards,
Cedrick Gaillard
Best regards, Cedrick Gaillard
mobidyc
Trusted Contributor

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

Hello,

under solaris, you have pkill for kill process, there is a small equivalent for HP-UX.

the syntax is:
pkill -U

process is a processname, fo example:
pkill -U root bdaemon

first, it will kill the process normally, if that don't work, it will do a kill -11, if that still don't work, it will kill -9 the process.

Regards,
Cedrick Gaillard
Best regards, Cedrick Gaillard