System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

favorite sysadmin scripts you always keep around (3)

 
SOLVED
Go to solution
mobidyc
Trusted Contributor

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

Hello,

if you'r- out of memory ( in your brain, not the server;) ), here is the perfect alias:

alias sepath='echo ${PATH} | tr ":" "\n" | xargs ls |sort -u |egrep -i "${@}"'

you can test:
# sepath grep
egrep
fgrep
grep
nisgrep
zgrep

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

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

Hello,

if you want to send a root terminal to your colleague and have a log of waht heis typing, this script is made for you (it's not made by me).

work for HP-UX and other Unix systems.
the logfile is /usr/local/log/sendxterm.${user}.`date +%Y%m%d`.`date +%H%m%S`.$$.log

the syntax is:
sendxterm -d 192.168.1.2

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

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

Hello,

if your ssh connexion seems too long, you can purge your [uwb]tmp files, this script attached will do it for you.

example before the purge,
/var/adm/wtmp was 239Mo :
# time ssh nr0u0151 "uname -n"
nr0u0151
real 0m58.58s
user 0m0.09s
sys 0m0.02s

after the purge of /var/adm/wtmp:
# time ssh nr0u0151 "uname -n"
nr0u0151
real 0m1.73s
user 0m0.09s
sys 0m0.01s

Regards,
Cedrick Gaillard
Best regards, Cedrick Gaillard

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

When someone takes the time to create a man page, it would be nice to have access to it.

Here is a script to verify all man pages are at your finger tips.

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

Here is a script to check free space on all file systems based on percentage used with email notificaion.

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

Parameter file for previous check_free_space script.
drb_1
Occasional Advisor

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

Two problems and the solutions I've been using for more than two decades.



Problem:
Oops! I didn't want to delete that:

Solution:
del (reversible rm)

Usage:
Once in the habit of using del path [...]
rather than rm path [...], accidental deletions can be restored from the ~/.deleted directory. Weekly, I purge the ~/.deleted directory of files more than 7 days old.
Emacs and other packages are configured to put their backups in ~/.deleted, thus reducing filespace clutter.



Problem:
Users complain of mysterious package failures when they run setup scripts too often and exceed environment string length,
causing misconfiguration.

Solution:
Idempotent path extension. i.e. If already in path variable, move to front of list and remove duplicate.

Usage:
This snippet is modified and incorporated into scripts that setup a user's environment for particular package use. Thereafter the user simply runs the setup script before using the package. If there are two or more users, one can execute the script before every usage, and the other may execute the script only once, but neither complains of failure due to exceeding environment string length.



Hopefully helpful,
Ninad_1
Honored Contributor

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

Hi,

Two small scripts for lan connectivity

1.To check which are the lan ports connected to the lan switches, if you have multiple lan ports connected but not assigned ip addresses.

lanscan | awk '{print $2,$5}' | tail +3 | while read mac ppa
do
linkloop -i $(echo $ppa | sed -e 's/lan//g') $mac 1> /dev/null 2>&1
if [[ "$?" = 0 ]]
then
echo $ppa connected
fi
done


2. To check which lan ports of one server are accessible to the lan ports of other server at the Link layer. This is mostly useful when you are doing the connectivity for Cluster, providing redundant links using redundant switches and lan ports.
This requires remsh/rcp to be enabled on the 2 servers/ can replace by ssh and scp as appropriate

remsh server2 -n "/usr/sbin/lanscan > /tmp/lanscansrv2.out"
rcp server2:/tmp/lanscansrv2.out /tmp
cat /tmp/lanscansrv2.out | tail +3 | awk '{print $2,$3}' | while read addr ppa
do
lanscan | tail +3 | awk '{print $2,$3}' | while read selfaddr selfppa
do
linkloop -i $selfppa $addr > /tmp/linkloop.out 2>&1
OK=$(grep -c OK /tmp/linkloop.out)
if [[ "$OK" = "1" ]]
then
echo "server1: lan$selfppa $selfaddr can reach server2: lan$ppa $addr"
fi
done
done



Regards,
Ninad
Ninad_1
Honored Contributor

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

Hi again,

Again 2 small scripts for checking mirroring on vg00.

1. Check mirror status of lvols in /dev/vg00. This can be useful to check how much of mirroring is completed if you running mirroring in background

for LVNAME in $(vgdisplay -v /dev/vg00 | grep 'LV Name' | awk '{print $NF}')
do
MIRROR=$(lvdisplay -v $LVNAME | grep 'Mirror copies' | awk '{print $NF}')
if [[ $MIRROR != 0 ]]
then
totalext=`lvdisplay -v $LVNAME | awk '/Logical extents/,/zzz/' | egrep -v
"^$" | tail +3 | wc -l`
syncedext=`lvdisplay -v $LVNAME | awk '/Logical extents/,/zzz/' | egrep -
v "^$" | tail +3 | awk '{print $NF}' | grep -c current`
echo "Mirroring for $LVNAME is $(echo "($syncedext*100)/$totalext" | bc)
% completed"
fi
done


2. Check stale PEs in mirrored lvols in /dev/vg00. This can be run as a shceduled job to regularly check if all lvols have synced PEs/mirroring

for lvname in $(vgdisplay -v /dev/vg00 | grep 'LV Name' | awk '{print $NF}')
do
MIRROR=$(lvdisplay -v $lvname | grep 'Mirror copies' | awk '{print $NF}')
if [[ $MIRROR != 0 ]]
then
MIRROR_STATUS=$(lvdisplay -v $lvname | grep -c -i stale)
if [[ $MIRROR_STATUS != 0 ]]
then
echo $lvname has stale PEs
else
echo $lvname is mirrored
fi
fi
done


Regards,
Ninad
Hakki Aydin Ucar
Honored Contributor

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

A script tells total Disk size on the server;

#!/usr/bin/sh
#strt=$(ioscan -funC disk | awk '/rdsk/{print $2}')
# Following part modified from Radhakrishnan's script . . .
#
strt=$(ioscan -funC disk |awk '{ if ($3 != "") printf ("%s",$0) ; else printf ("%s\n",$0)}' |grep -v DVD-ROM | grep -v Class | awk '/rdsk/{print $10}')

i=0
p1=0
pT=0

echo $strt > /tmp/siliniz
clear
for i in `cat /tmp/siliniz`
do
p1=$(diskinfo -b $i)
pT=$(expr $p1 + $pT)
done
Tot=$(expr $pT / 1048576)
echo "-------------------------"
echo " Total Disk Size: $Tot GB"
/usr/bin/rm /tmp/siliniz