Operating System - HP-UX
1838577 Members
4796 Online
110128 Solutions
New Discussion

favourite sysadmin scripts you always keep around....

 
SOLVED
Go to solution
Thomas D. Harrison
Frequent Advisor

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

idmenu
Used regularly on 11.0

This is a menu script for removing UserIDs.
It prevents the removal of system IDs and any IDs that have BatchID in its description. It also verifies that the ID has "home" in it's home directory.

The script shows the date all of the ID's home directory files were last accessed ( to ensure that a script that runs isn't using it etc...).

The script then tars the directory into /sysadm/old.ids/ for a quick restore if needed.

The script will need to be reviewed for appropriate directories etc...
Imbibo ergo sum.
Yogeeraj_1
Honored Contributor

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

Hello,
another good one.

Sending files by batch to several server using ftp. We use it everyday.

batchftp [ ]

best regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

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

Hi again,

This one i got from HP.

Helps me document my server configuration. Generates a report as below:
-----------------------------------------------
cstm>selclass qualifier cpu;info;wait;infolog
-- Information Tool Log for CPU on path 160 --
Log creation time: Fri Jun 14 09:01:12 2002
Hardware path: 160

Product ID: CPU Module Type: 0
Hardware Model: 0x5c9 Software Model: 0x4
Hardware Revision: 0 Software Revision: 0
Hardware ID: 0 Software ID: 541706567
Boot ID: 0x2 Software Option: 0x91
Hard Physical Address: 0xfffa0000 Soft Physical Address: 0
Slot Number: 8 Software Capability: 0x100000f0
PDC Firmware Revision: 40.19 IODC Revision: 0
Instruction Cache [Kbyte]: 512 Processor Speed: N/A
Data Cache [Kbyte]: 1024 Processor State: N/A
Instruction TLB [entry]: 160 Processor Chip Revisions: 2.4
Data TLB Size [entry]: 160 2nd Level Cache Size:[KB] N/A
Serial Number: 0

-------------- Memory Error Log Information --------------
Bus 0 Log Information

No errors logged for this bus

------------ I/O Module Error Log Information ------------
No I/O module errors logged

WARNING: The non-destructive test bit was set, so memory was not tested
destructively. Information only, no action required.

WARNING: One or more DIMMs in the system were not made by HP.

Module Revision
------ --------
System Board A43938
PA 8500 CPU Module 2.4
-----------------------------------------------

Nice script.

Best Regards
Yogeeraj
PS. oops! you will need stm installed on your machine. ;)
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
H.Merijn Brand (procura
Honored Contributor

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

In respons to all the 'ps' and 'kill' utilities, here's my perl scripts that do more like that

1. px

A perl script that uses the portable Proc::ProcessTable module (also works on AIX and such), accepting ps options and patterns, showing the most interesting columns (IMHO)

2. px-ps

Similar to px, but predates the Proc::ProcessTable module and uses ps parsing

3. killdown

Shows processes in relation to eachother, and enables to kill a whole process tree

4. curses.pl

Used by px and px-ps to make the headers use screen attributes

5. Getopt::Long-2.31

The most recent Getopt::Long module, part of the CORE perl distribution, but I use more recent features, requiring newer versions of this module than shipped with perl-5.6.1

6. Proc::ProcessTable-0.34.tgz

The most recent Proc::ProcessTable module. Very much worth looking at if you want system independant scripts wrt ps

Have (a lot of) fun!

BTW I use px zillions of times a day, and almost never use ps anymore
Enjoy, Have FUN! H.Merijn
Sukant Naik
Trusted Contributor

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

This is a simple script which I used to kill processes of certain type

eg: I want to kill processes of user sukant

# for i in `ps -ef|grep sukant | cut -c 10-14`
> do
> kill -9 $i
> done

Regards,

Sukant
Who dares he wins
Ernesto Cappello
Trusted Contributor

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

This script can be used to send by e-mail some daily backup report with OmniBack II 3.50 maybe in a cron.

# !/bin/sh
# Script to send by e-mail statistics on some backup report

# 1) "LIST OF BACKUP SESSION"
# 2) "CLIENT STATISTICS"
# 3) "SESSION OBJECT REPORT"
#
datestr=`date '+%Y/%m/%d'`

#### LIST OF BACKUP SESSION ####

/opt/omni/bin/omnirpt -report list_sessions -timeframe 24 24 -html -email MY-EMAIL_ADDRESS


#### SESSION OBJECT REPORT ####

/opt/omni/bin/omnirpt -report session_objects -session $datestr-1 -html -email MY-EMAIL_ADDRESS
/opt/omni/bin/omnirpt -report session_objects -session $datestr-2 -html -email MY-EMAIL_ADDRESS


#### CLIENT STATISTICS ####

/opt/omni/bin/omnirpt -report host_statistics -timeframe 24 24 -html -email MY-EMAIL_ADDRESS

#### LIST MEDIA ####

/opt/omni/bin/omnirpt -report media_list -html -email MY-EMAIL_ADDRESS

I've 2 session objet in my office backup $datestr-1 and $datestr-2 .... in a my script session (#### SESSION OBJECT REPORT ####)
Naturally you must replace instead of MY-EMAIL_ADDRESS his/her own e-mail address.
For further information and other report look "man omnirpt".
Regards
Ernesto.
Bill McNAMARA_1
Honored Contributor

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

I like that one Sukant!
I'm going to have fun with that!
PS: know what happens if you enter root? ;)

Later,
Bill
It works for me (tm)
John Eaton
Frequent Advisor

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

Seems I posted a new message (http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x2c87107d277ad611abdb0090277a778c,00.html
) rather than a response to this one. Oops
I'll try again...

I've written a report to generate an HTML email report of the previous days OmniBack backups, restores and used media, with color codes and clickable links.
It's in the attachment as a shar file. It expands to 3 files, and shell wrapper, a perl script and a cgi perl script.
We run the shell script from cron each morning and it delivers 2 versions - 1 for the admins, and one for managers and team leads.
I tweaked it to remove site specific stuff, but it's self documented as to how to set it up, and my email is in there as well. Written with Perl5, HP-UX 10.20 and OmniBack 3.0. Fairly generic, but ya never know...
Cheers,
John
Yogeeraj_1
Honored Contributor

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

Hi,

This script is really helpful to me each time i need to kill blocking telnet user sessions from my server.

==> kick a user (deg) out of the system ;)

Execution:
L1000: home/deg>kick


-------------------------------
o o o oooo o o
o o o o o o o
oooo o o oooo
o o o o o o
o o o o o o o
o o o oooo o o
-------------------------------

0 to cancel
ENTER USER : deg

I know many of you will find this simple script very useful.

Cheers
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
George A Bodnar
Trusted Contributor

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

This contains 2 scripts and 2 c programs (source code) that are used to show information on Omniback backups within a certain time range.

The C programs are simple date manipulation programs that we use in a lot of our scripts to do things like get the date/time from 3 hours ago, 10 days from now, etc. Simply compile them to the same name as the c program without the extension - these compile fine an a number of other UNIX platforms.

The omni_audit.ksh shell script is the main one in this bunch which can show 1 of 2 things:

1) Failed sessions within the last X hours including a guess at the reason for the failure. VERY useful for large Omniback shops that tend to have at least a few failures each night.

2) Session queuing for the last X hours. Once again useful to help balance your Omniback schedule. One warning - the data this uses seems to get reset when you cycle Omniback so trying to see 5 weeks ago data probably won't show you very much.

Last warning - the filters used to parse output may need altered (see MSExchange) for shops using modules like Oracle, etc. since they change the name of sessions a bit. We only have the Exchange/Exchange 2000 filters so I dump this when creating output.

Sample output:

omni_audit.ksh: Generating list of sessions...
omni_audit.ksh: Checking for jobs that ended unsuccessfully.

Omniback failed jobs between Fri Jun 14 10:17:00 2002 and Sat Jun 15 10:17:00 2002

Datalist Session Status Reason Action

server.full 2002/06/14-26 Aborted I/O drive1 NA
** Rerun attempt 2002/06/14-28 Completed SUCESSFUL NA

*** Total Backups : 100
*** Total Successes : 100 (100.00%)
*** Total Failures : 0 (0.00%)
Greg Stark_1
Frequent Advisor

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

Attached is a script called sys_info.sh that I run monthly on all of our servers for disaster recovery. After running it ftp's the info to our webserver. I used some code from this forum, thanks again, and some of my own.

It also converts the txt to html for the web. It isn't pretty, but it does the job.

Let me know if you think there is something missing.

Thanks,
Greg
Dave La Mar
Honored Contributor

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

I got tired of the CE constantly asking me if I would get some files and email them to him.
Now when he comes in, he uses the attached script to email any number of attachments to the email address of his choice.
And yes, we do have security measures in place.
HP-UX 11.0
"I'm not dumb. I just have a command of thoroughly useless information."
Anthony khan
Frequent Advisor

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

Hi Bill, Sorry I was late, but remember its never too late, here's my mediawrite script.
Donald Kok
Respected Contributor

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

When a new user enters the company, I get the request for a new user promptly. When a user leaves, I do not hear anything.

However, our helpdesk does know who left the comany. So I made a script that sends a trimmed version of the passwd-file to the helpdesk with the kind request to check it for gone users.

So, once in a while I find a list on my desk with the users I can remove.
Here is the script:

#!/bin/sh
/usr/bin/cat /etc/passwd | /usr/bin/cut -f1,5 -d: | /usr/bin/grep -v amor | /usr/bin/grep -v root | /usr/bin/grep -v daemon | /usr/bin/grep -v bin | /usr/bin/grep -v sys | /usr/bin/grep -v adm | /usr/bin/grep -v uucp | /usr/bin/grep -v lp | /usr/bin/grep -v nuucp | /usr/bin/grep -v hpdb | /usr/bin/grep -v nobody | /usr/bin/grep -v ingres | /usr/bin/grep -v behehv | /usr/bin/grep -v ohoan | /usr/bin/grep -v wapla | /usr/bin/grep -v golmp | /usr/bin/grep -v tftp | /usr/bin/grep -v pcs | /usr/bin/grep -v hmmodel | /usr/bin/grep -v hmso | /usr/bin/grep -v rwslod | /usr/bin/grep -v lmpipe | /usr/bin/grep -v lmguest | /usr/bin/grep -v arcinfo | /usr/bin/grep -v simadm | /usr/bin/sort | /usr/bin/elm -s "please check the left users " helpdesk@mycompany.nl
My systems are 100% Murphy Compliant. Guaranteed!!!
George Abraham_1
Regular Advisor

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

hai

I got a small script to find the clock speed of system CPUS



if [ "`uname -r | cut -d. -f2`" = "11" ]
then ADB="adb -k"
else ADB="adb"
fi

echo "itick_per_tick/D" | ${ADB} /stand/vmunix /dev/kmem | awk 'NF == 2 {print $2 / 10000}'`



cheero
George
keep smiling
Bob Moore_1
Advisor

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

Here's a script that i put together to take a bunch of downloaded patches and put them into a depot. It will ask some questions about the patches that are downloaded and put them in the appropriate subdirs. It works well for us, and makes getting patches deployed alot faster. I hope you can use it to.

Later,
BOB
Steve Post
Trusted Contributor

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

two very small things that I use a lot.

Remove control-M's from a windows text file.
cat $1 | tr -d "\015"

Set your xwindows display variable
#!/bin/ksh
FRMHST=`who am i -u | awk -F"\ *" '{print $8}'`
DISPLAY=${FRMHST}:0.0
export $DISPLAY
echo DISPLAY var set to $DISPLAY

Steve Post
Trusted Contributor

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

don't want to run xomni to see the status?
Have this cronjob send you the morning report with the results of last nights backups.


Mark Greene_1
Honored Contributor

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

If you have a postscript file that you only want to print certain pages of, but don't have ghostscript or other postscript savy editor, this script is for you:

#!/bin/ksh
# extracts page(s) from a ps file into a new ps file
# assumes the use of %%Pages: (atend) in the prolog
###

PAGE_CNT=0
FILE= # source file name here
NEW_FILE= # target file name here
cat /dev/null>$NEW_FILE
TEMP_FILE=/tmp/temp_ps.$$ # this is a work file and gets deleted at
the end
STRING= # unique string to search to id the page(s) needed
QUOTE="'"

TOP=`grep -n "%%EndProlog" $FILE|cut -d":" -f1`
head -$TOP $FILE >$NEW_FILE
OLD_IFS=$IFS
egrep -n "$STRING|%%Page" $FILE|grep -v "Pages">$TEMP_FILE
exec 3<$TEMP_FILE
while read -u3 LINE; do
IFS=:
set $LINE
if [ "${2}" = "%%Page" ]; then
HOLD_ROW=$1 # remember this row number
STRING_FOUND=0
elif [ "${2}" = "%%PageTrailer" ]; then
if [ "${STRING_FOUND}" -eq 1 ]; then
END_ROW=$1p # last row of page
CMD="-n $QUOTE$START_ROW,$END_ROW$QUOTE"
eval "sed $CMD $FILE >>$NEW_FILE"
(( PAGE_CNT = $PAGE_CNT + 1 ))
fi
else
START_ROW=$HOLD_ROW # previous %%Page row is start of page
STRING_FOUND=1
fi
IFS=$OLD_IFS
done

# add ending comments to ps file #
TOTAL_PAGES=$PAGE_CNT # end of document
echo "%%Trailer" >>$NEW_FILE
echo "%%Pages: "$PAGE_CNT >>$NEW_FILE
echo "%%EOF" >>$NEW_FILE
IFS=$OLD_IFS
rm -i $TEMP_FILE
### end of script ###
the future will be a lot like now, only later
Vicente Sanchez_3
Respected Contributor

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

Here it's my contribution.

A small script to create the mirror of the boot disk.

Regards, Vicente.
Holger Knoppik
Valued Contributor

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

Hi again Bill !

little script to store smb.conf information by testparm regarding multiple fileserver instances:

---snip---
#!/bin/sh
#
#set -x

PATH=$PATH:/opt/samba/bin
LOGDATE='date +%d%m%y-%H%M%S'

usage () {
echo "USAGE: $0 "
}

if [ $# != 1 ]
then
echo "ERROR in usage"
usage
exit 1
fi

INST=$1
case $INST in
INSTANCE1) CONF=/etc/opt/samba/smb.conf.instance1
LOG=/var/opt/samba/inst1/logs/conf.`$LOGDATE`
;;
INSTANCE2) CONF=/etc/opt/samba/smb.conf.instance2
LOG=/var/opt/samba/inst2/logs/conf.`$LOGDATE`
;;
INSTANCE3) CONF=/etc/opt/samba/smb.conf.instance3
LOG=/var/opt/samba/inst3/logs/conf.`$LOGDATE`
;;
*) echo "ERROR: $INST is an unknown instance"
usage
exit 1
esac

(
date
testparm $CONF <> $LOG
EOF
)
echo "CONFIG STORED IN $LOG"
---snip---

RGDS, Holger
Live long and prosper!
Paula J Frazer-Campbell
Honored Contributor

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

HI
Not a scipt but a tweak.

Create in /usr/bin a file:-

mail(your initials) ie.

mailpjfc.

Give it execute permissions.

It should contain one line:-

mailx -s "From " YOUR@EMAIL.ADDRESS.

So you want to transfer a file to your desktop then.

cat | mailpjfc
or:-
strings | mailpjfc
or:-
what | mailpjfc


Paula
If you can spell SysAdmin then you is one - anon
John Dvorchak
Honored Contributor

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

One simple one that I wrote to issue the same command on multiple systems. I also check for a list of restricted words like rm, mv etc. so I don't mess up and rm -rf the root directory.

#!/usr/bin/ksh
USAGE="usage:rrun 'command' < i.e, uname -a or who -r >"

# Get command to run from command line

COMMAND=$*

# Check to see if it is blank

if [[ $COMMAND = "" ]]
then
print $USAGE
exit 1
fi

# Check for rm, mv, shutdown and other nasty commands and shut it down
# Enter your list of restricted commands below

if [[ "$COMMAND" = +(*rm*||*mv*||*reboot*||*shutdown*||*init*) ]]
then
echo
echo "******************************************"
echo
echo "Your command: $COMMAND"
echo "Will not allow rm, mv, init, reboot or shutdown!"
echo
echo "******************************************"

exit 1
fi

# If the command is not blank and not nasty then do it

for i in `cat /usr/local/etc/rrun.conf` #Name of file containing system names
do
print "************************ $i ***************************"
# print "Running the following command on $i:$COMMAND"
print $COMMAND
remsh $i -n $COMMAND
# print "***********************************************************"
print
done
If it has wheels or a skirt, you can't afford it.
Pete Randall
Outstanding Contributor

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

Almost more of an alias that a script but very handy when your fingers get tired of typing ps -ef |grep.

Pete
David Child_1
Honored Contributor

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

The attached script is useful if you like(d) the functionality of EMC's PowerPath command:

powermt vgdisplay dev=all

The vgdisplay option was removed after PowerPath 1.5, but it provided a nice look at your EMC disks and where they were being used.

After we upgraded I wrote the attached. It can definately use a little cleanup and would probably run faster by drawing on powermt instead of syminq, but it works.

Here is a sample output:

S Y M M E T R I X

Mcode Cache Num Phys Num Symm
SymmID Attachment Model Version Size (MB) Devices Devices

000182401709 Local 3700 5265 8192 56 402
000182403007 Local 3700 5265 6144 82 309


=========>> Device: 0703A000 <<==========
/dev/dsk/c8t0d0: /dev/vgarbortest2
/dev/dsk/c10t0d0: /dev/vgarbortest2

=========>> Device: 0703B000 <<==========
/dev/dsk/c8t0d1: /dev/vgias_empr_test1
/dev/dsk/c10t0d1: /dev/vgias_empr_test1

=========>> Device: 0703C000 <<==========
/dev/dsk/c8t0d2: /dev/vgarbortest4
/dev/dsk/c10t0d2: /dev/vgarbortest4

=========>> Device: 0703D000 <<==========
/dev/dsk/c8t0d3: FREE
/dev/dsk/c10t0d3: FREE

=========>> Device: 0703E000 <<==========
/dev/dsk/c8t0d4: /dev/vgarbortest0
/dev/dsk/c10t0d4: FREE

...

As you can see, it lists each path to the same device. Note the last entry - it is showing FREE on one path because the PV Link was not set up.

David