Operating System - HP-UX
1833777 Members
1968 Online
110063 Solutions
New Discussion

favourite sysadmin scripts you always keep around....

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

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

what didn't you use swverify -f ?

Later,
Bill
It works for me (tm)
Larry Reinhart
Advisor

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

Here are a couple of scripts that I created in
order to correctly print formatted output to
printers attached to PC's running MS Windows.

The 1st script is lp.1020 and is an lp wrapper
script. The documentation on how to use the
script is within the script itself. Basically
it "replaces" /usr/bin/lp (which is renamed to
lp.bin). It preformats the output using HP's
own print drivers and then sends that output
as raw output to the printer connected to the
PC.

The 2nd script is just an installation script
for lp.1020. (i had too many servers to
add this to by hand :-)

NOTE: this was not tested on 11.x. This will
work on 9.0x with modification of the
directories from /var to /usr.

I hope these scripts are helpful. :-)
Larry
Dietmar Konermann
Honored Contributor

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

Hi, Bill!

Since there were hundreds of files with wrong permissions I needed an automatic way to fix them. The swlist output is much easier to parse... why should I use the swverify results?

After running the script you may use swverify to verify the results...

Regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Shannon Petry
Honored Contributor

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

Some goodies for printing graphic X-windows to PCL printers. Handles accounting and remote printing from non-hp systems ;)

Make sure to configure the PRINTER AND PCLTRANS_HOST in the quickshot script.

I also have a button created for CDE as well as desktop definitions so users simply click a button and out comes a pretty picture. Handles remote printing so that the script workes on non HP-UX systems. Note you must configure either ~/.rhosts or /etc/hosts.equiv for remsh with 0 auth.

Since I can only attach 1 file, the buttons and CDE definitions will cost ya! hehe

Have fun!
Shannon
Microsoft. When do you want a virus today?
Shannon Petry
Honored Contributor

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

Okay, here is the icon and CDE files. just cut and paste, names are even in the notes.

Forgot to mention that my accounting section requires NIS (lazy and not recoding that part). If you need accounting and are not running NIS then feel free to hack away.
If you dont need accounting then keep it set to 0!

Have more fun!
Shannon
Microsoft. When do you want a virus today?
John Meissner
Esteemed Contributor

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

 
All paths lead to destiny
John Meissner
Esteemed Contributor

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

I forgot to mention that after you run the above script you will need to ignite the disaster recovery server. this will RECREATE ALL THE LVOL's AUTOMATICALLY. :) that should save some time
All paths lead to destiny
John Meissner
Esteemed Contributor

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

This script will show you all accounts that have not been active in the past 60 days.

#! /usr/bin/ksh
#this script will work but is not as accurate as /var/adm/scripts/NIS_activity_log.sh
#or /var/adm/scripts/activity_log.sh (for non-NIS machines)
#this file will examine when the last activity of a user is
#written by John Meissner on 4/23/2002
BOLD="`tput smso`"
NORMAL="`tput rmso`"
if [ `id|cut -c5-11` != "0(root)" ]
then
echo "Quitting - You must run this script as Root"
exit 1
fi
################################# setting up variables ############################
month=$(date | awk '{print $2}')

Jan=1
Feb=2
Mar=3
Apr=4
May=5
Jun=6
Jul=7
Aug=8
Sep=9
Oct=10
Nov=11
Dec=12
############################## running script ####################################

if [ $month = Jan ]
then mdate=$Jan
elif [ $month = Feb ]
then mdate=$Feb
elif [ $month = Mar ]
then mdate=$Mar
elif [ $month = Apr ]
then mdate=$Apr
elif [ $month = May ]
then mdate=$May
elif [ $month = Jun ]
then mdate=$Jun
elif [ $month = Jul ]
then mdate=$Jul
elif [ $month = Aug ]
then mdate=$Aug
elif [ $month = Sep ]
then mdate=$Sep
elif [ $month = Oct ]
then mdate=$Oct
elif [ $month = Nov ]
then mdate=$Nov
elif [ $month = Dec ]
then mdate=$Dec
fi

((mdate2=$mdate-1))

if [ $mdate2 = 1 ]
then month2=Jan
elif [ $mdate2 = 2 ]
then month2=Feb
elif [ $mdate2 = 3 ]
then month2=Mar
elif [ $mdate2 = 4 ]
then month2=Apr
elif [ $mdate2 = 5 ]
then month2=May
elif [ $mdate2 = 6 ]
then month2=Jun
elif [ $mdate2 = 7 ]
then month2=Jul
elif [ $mdate2 = 8 ]
then month2=Aug
elif [ $mdate2 = 9 ]
then month2=Sep
elif [ $mdate2 = 10 ]
then month2=Oct
elif [ $mdate2 = 11 ]
then month2=Nov
elif [ $mdate2 = 0 ]
then month2=Dec
fi

find /home -name .sh_history | awk '{print "ll " $1}' > /tmp/hist
chmod +x /tmp/hist
echo "${BOLD} Most recent user login activity shown ${NORMAL}"
echo "${BOLD} User Month Date Time ${NORMAL}"
/tmp/hist | awk '{print $3 " " $6 " " $7 " " $8}' | grep -v $month | grep -v $month2 >> /tmp/hist.log
more /tmp/hist.log
rm /tmp/hist
rm /tmp/hist.log
All paths lead to destiny
John Meissner
Esteemed Contributor

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

This script will show users who have never logged in or who have not logged in within the past 60 days for an NIS server.

#! /usr/bin/ksh
#this script is intended to run only on NIS enabled machines
#this file will examine when the last activity of a user is
#written by John Meissner on 4/23/2002
BOLD="`tput smso`"
NORMAL="`tput rmso`"
if [ `id|cut -c5-11` != "0(root)" ]
then
echo "Quitting - You must run this script as Root"
exit 1
fi
################################# setting up variables ############################
month=$(date | awk '{print $2}')

Jan=1
Feb=2
Mar=3
Apr=4
May=5
Jun=6
Jul=7
Aug=8
Sep=9
Oct=10
Nov=11
Dec=12
############################## running script ####################################

if [ $month = Jan ]
then mdate=$Jan
elif [ $month = Feb ]
then mdate=$Feb
elif [ $month = Mar ]
then mdate=$Mar
elif [ $month = Apr ]
then mdate=$Apr
elif [ $month = May ]
then mdate=$May
elif [ $month = Jun ]
then mdate=$Jun
elif [ $month = Jul ]
then mdate=$Jul
elif [ $month = Aug ]
then mdate=$Aug
elif [ $month = Sep ]
then mdate=$Sep
elif [ $month = Oct ]
then mdate=$Oct
elif [ $month = Nov ]
then mdate=$Nov
elif [ $month = Dec ]
then mdate=$Dec
fi

((mdate2=$mdate-1))

if [ $mdate2 = 1 ]
then month2=Jan
elif [ $mdate2 = 2 ]
then month2=Feb
elif [ $mdate2 = 3 ]
then month2=Mar
elif [ $mdate2 = 4 ]
then month2=Apr
elif [ $mdate2 = 5 ]
then month2=May
elif [ $mdate2 = 6 ]
then month2=Jun
elif [ $mdate2 = 7 ]
then month2=Jul
elif [ $mdate2 = 8 ]
then month2=Aug
elif [ $mdate2 = 9 ]
then month2=Sep
elif [ $mdate2 = 10 ]
then month2=Oct
elif [ $mdate2 = 11 ]
then month2=Nov
elif [ $mdate2 = 0 ]
then month2=Dec
fi
print $month $month2 > /tmp/mlist

more /etc/passwd.nis | sed 's/:/ /g' > /tmp/hist
more /tmp/hist | awk '{print $1}' > /tmp/hist2

number=$(wc -l /tmp/hist2 | awk '{print $1}')
((number2=$number+1))
count=0
while [ "$count" != "$number2" ]
do

sed -n '1p' /tmp/hist2 > /tmp/finger_user.list
tuser=$(cat /tmp/finger_user.list)
finger $tuser | egrep -i 'Last|Never' > /tmp/finger_user.list2
paste /tmp/finger_user.list /tmp/finger_user.list2 >> /tmp/user.info

more /tmp/hist2 | sed -n '2,$p' > /tmp/hist2a
mv /tmp/hist2a /tmp/hist2
let "count += 1"
done

echo " Users who have not logged in within the past 60 days on $hostname "
more /tmp/mlist | awk '{print "more /tmp/user.info | egrep -i \"Last|Never\" | grep -v " $1 " | grep -v " $2 }' > /tmp/inactive
chmod +x /tmp/inactive
#you can output the results of this script to a file by redirecting the command below as such:
#/tmp/inactive > filename
/tmp/inactive

rm /tmp/hist
rm /tmp/hist2
rm /tmp/mlist
rm /tmp/finger_user.list
rm /tmp/finger_user.list2
rm /tmp/user.info
rm /tmp/inactive
All paths lead to destiny
John Meissner
Esteemed Contributor

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

This is a quick little script that will convert a printer from portrait to landscape. When running this script you must type the script followed by a space and then the name of the printer to be changed. i.e. ./command printername

#! /usr/bin/ksh
pntr=$1
echo $pntr
sed 's/orientation\=\"def\"/orientation\=\"l\"/' /etc/lp/interface/model.orig/$pntr > /etc/lp/interface/model.orig/tmp.lp
mv /etc/lp/interface/model.orig/tmp.lp /etc/lp/interface/model.orig/$pntr
sed 's/pitch\=\"def\"/pitch\=\"13\.7\"/' /etc/lp/interface/model.orig/$pntr > /etc/lp/interface/model.orig/tmp.lp
mv /etc/lp/interface/model.orig/tmp.lp /etc/lp/interface/model.orig/$pntr
sed 's/textlen\=\"def\"/textlen\=\"66\"/' /etc/lp/interface/model.orig/$pntr > /etc/lp/interface/model.orig/tmp.lp
mv /etc/lp/interface/model.orig/tmp.lp /etc/lp/interface/model.orig/$pntr
sed 's/vsi\=\"def\"/vsi\=\"5\.4\"/' /etc/lp/interface/model.orig/$pntr > /etc/lp/interface/model.orig/tmp.lp
mv /etc/lp/interface/model.orig/tmp.lp /etc/lp/interface/model.orig/$pntr
echo " $1 is now setup for landscape printing"
All paths lead to destiny
John Meissner
Esteemed Contributor

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

 
All paths lead to destiny
John Meissner
Esteemed Contributor

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

This script will automatically telnet into a box for you. note: it is not secure. It does work though.
Requires: "expect"

#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Thu May 9 13:48:07 2002
# Expect and autoexpect were both written by Don Libes, NIST.
#
# Note that autoexpect does not guarantee a working script. It
# necessarily has to guess about certain things. Two reasons a script
# might fail are:
#
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts. If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character. This
# pacifies every program I know of. The -c flag makes the script do
# this in the first place. The -C flag allows you to define a
# character to toggle this mode off and on.

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}

#
# 2) differing output - Some programs produce different output each time
# they run. The "date" command is an obvious example. Another is
# ftp, if it produces throughput statistics at the end of a file
# transfer. If this causes a problem, delete these patterns or replace
# them with wildcards. An alternative is to use the -p flag (for
# "prompt") which makes Expect only look for the last line of output
# (i.e., the prompt). The -P flag allows you to define a character to
# toggle this mode off and on.
#
# Read the man page for more info.
#
# -Don


set timeout -1
spawn telnet mou065
match_max 100000
expect -exact "
\r
login: "
send -- "username\r"
expect -exact "username\r
Password: "
send -- "password\r"
send -- "clear\r"
expect -exact "clear\r"
interact
All paths lead to destiny
John Meissner
Esteemed Contributor

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

#! /usr/bin/ksh
#written by John Meissner
#This script will read the /etc/passwd or the /etc/passwd.nis file depending; and create the home directories and grant the propper permissions to
#the /home/$logname directories.

echo " Is an NIS server (y/n) "
until [ "$answer" = "y" ] || [ "$answer" = "Y" ] ||
[ "$answer" = "n" ] || [ "$answer" = "N" ] ; do
echo " Answer with (y/n) !\c"
read answer
done
case $answer in
y|Y)
var1=$(cat /etc/passwd.nis | grep -v root | grep -v lp | grep -v bin | grep -v sys | grep -v daemon | grep -v adm | awk -F: '{print $1}')
for i in $var1
do
mkdir -p /home/$i
unset $var1
done
;;
n|N)
var1=$(cat /etc/passwd | grep -v root | grep -v lp | grep -v bin | grep -v sys | grep -v daemon | grep -v adm | awk -F: '{print $1}')
for i in $var1
do
mkdir -p /home/$i
unset $var1
done
esac

#this lines will chown and chgrp the users directory so that
#the user will own their home directory and the group "users" will be the group ID
#this must be copied and run from the /home directory on the desired server
cd /home
ll /home | awk '{print $9}' | grep -v lost+found | grep -v opc_op | grep -v root | grep -v sys | grep -v daemon | grep -v adm | grep -v sys | grep -v lp > ulist
cat /home/ulist | awk '{print "chown " $1 ":users "$1}' > glist
chmod +x glist
./glist
rm ulist glist
All paths lead to destiny
John Meissner
Esteemed Contributor

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

I hate typing redundant things so I wrote this to quickly export my display and launch a program for me. In this case I'm launching Service Control Manager but you can change this to launch any Program.

#! /usr/bin/ksh
cd /opt/mx/bin
var1=$(who -mT | sed -e 's/.*[ ]\([^ ]*\)$/\1/')
export DISPLAY=$var1:0.0
/opt/mx/bin/scmgr &
All paths lead to destiny
John Meissner
Esteemed Contributor

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

this script will tell you how many times a user loged in each month over the past year.
Usage: logstats username

#! /bin/sh
# loginstat: login accounting by usr/month
# @(#): loginstat.SH,v 0.1 1997/30/10 12:30:05 MET Exp $
# By Luke Th. Bullock # This script is Freeware, do what you like with it :)
#
if [ $# -eq 0 ] ; then
echo "usage: loginstat user|Month (-help for help)" 1>&2
exit 1
fi
if [ $1 = -help ]; then
cat <usage: user month (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
user - prints yearly stat
-help - prints this info
^C (CTRL+C) - Break|Stop Script
EOF
elif [ $2 ]; then
echo "`last $1|grep $2|wc -l` logins for $1 in $2"
else
echo "Login stats for $1 based on wtmp entries:"
for i in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
do
echo "`last $1|grep $i|wc -l` logins in $i"
done
fi
All paths lead to destiny
John Meissner
Esteemed Contributor

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

Hot off the presses. I wrote this to fix a problem while converting to NIS -

#! /usr/bin/ksh
#written by John Meissner
#this script will examine the /home directory for directories owned by a UID (orphaned because
#the user changed their UID and didn't change ownership of their files
#and reclaim all their files
touch files.list new_owner.sh owner.sh
rm new_owner.sh owner.sh files.list
touch new_owner.sh owner.sh files.list
ll /home/ | awk '{print $3,$9}' | grep [0-9] > home.list
cat home.list |
while read file
do
var1=$(cat home.list | sed -n '1p' | awk '{print $1}')
var2=$(cat home.list | sed -n '1p' | awk '{print $2}')
if [ "$var1" = "$var2" ]
then
sed -n 1d home.list > home.list2
mv home.list2 home.list
unset var1 var2
elif [ "$var1" != "$var2" ]
then
cat home.list | print "find / -user $var1 | awk '{print \"chown $var2 \" \$1}' >> new_owner.sh" >> owner.sh
unset var1 var2
sed -n 1d home.list > home.list2
mv home.list2 home.list
fi
done
chmod +x owner.sh
./owner.sh
chmod +x new_owner.sh
cat new_owner.sh
./new_owner.sh
rm owner.sh new_owner.sh
All paths lead to destiny
JHL_2
Advisor

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

Please remove Volckers script!!! Yea, it's not just the links that are the problem but the CONTECT of the links that is a problem. The volume of traffic it creates ain't great either. Now I'm reluctant to view any of the attachments.

Please remove his entry
Bill McNAMARA_1
Honored Contributor

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

well, rather than remove scripts - and Volkers is pretty harmless imho - why don't you attach improvements.! remember top points for tried and tested scripts only!

Later,
Bill
It works for me (tm)
fg_1
Trusted Contributor

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

I am attaching my jetdirect printer script here
which is the final tested product. This script when run will allow you to select a particular printer queue from a menu or all printers on the system and perform a status check on that printer.

Hope you enjoy it.

RAJESH GANGADHARAN
Regular Advisor

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

Hi
Here is perl script which gives the Total Allocated and Free size(in MB) of all the Volume Groups in a system

-Rajesh
Let the choices you make today be the choices you can live with tomorrow.
Dietmar Konermann
Honored Contributor

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

I believe this thread deserves to be revitalized. :)

This sets the title/icon of hpterm, dtterm and xterm. Likes to be added to /etc/profile.

# Set Window and Icon name
winIcon="$(hostname)"
winTitle="$winIcon $(uname -r) $(model)"
case "$TERM" in
dtterm|xterm)
echo "\033]1;$winIcon\007\c"
echo "\033]2;$winTitle\007\c"
;;
hp*|*2392*)
echo "\033&f-1k${#winIcon}D${winIcon}\c"
echo "\033&f0k${#winTitle}D${winTitle}\c"
;;
esac

Regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Tibi Baraboi_1
Advisor

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

Small script to clean old spool requests (older than 2 days). It assumes that your printers' name start with lp (our environment):

#!/usr/bin/ksh
# The script is cleaning all printer requests older than 3 days
# Script logs in /tmp/clear_spool.log
# TBA - 14/10/2002

my_month=`date | awk '{print $2}'`
echo "Month is: " $my_month
my_day=`date | awk '{print $3}'`
((my_day = $my_day -1))
#echo $my_day
echo "Delete jobs older than: " $my_day

old_request_list=`lpstat -i -o | grep ^lp | awk -v m=$my_month -v d=$my_day '{ if ( ($5 != m ) OR ( $6 < d) ) print $1 }'`

for i in $old_request_list
do
cancel $i
done
Bill McNAMARA_1
Honored Contributor

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

******** IMPORTANT *********
********** NOTICE **********






this is the official end of this branch of the subject!

The thread continues

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x836cc1c4ceddd61190050090279cd0f9,00.html

so post your contribiutions there from now on..

ZERO points to this thread from now on - even for efficient prime number generator scripts..


Thanks,
Bill









******** IMPORTANT *********
********** NOTICE **********
It works for me (tm)
Michael Campbell
Trusted Contributor

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

Simple but very handy, sort files and directories by size (blocks).

MC
Bill McNAMARA_1
Honored Contributor

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

******** IMPORTANT *********
********** NOTICE **********






this is the official end of this branch of the subject!


please post your contributions to:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x836cc1c4ceddd61190050090279cd0f9,00.html


and you'll get your points there!

Thanks,
Bill









******** IMPORTANT *********
********** NOTICE **********
It works for me (tm)