Any unix/linux sysadmins fancy sharing/writing some .sh scripts???

Associate
Joined
28 Jul 2004
Posts
553
Hi,

Basically we have a number of servers here running HP-UX, RedHat 2, 3, and 4... and I want to get some basic scripts running on them to perform some basic System Admin tasks. I was thinking that I would crontab the scripts and get them to email the results daily. Is this a reasonable idea?

The kind of .sh scripts I was thinking about are...

* show the available disk space on the server (using bdf or df -k), and send an email if the disk space is more than say 90% full on any drive.
* show which users have been logging into the servers... usernames they used, time/date, their IP's, etc.
* tail the syslog etc and send any errors.

I know this is not a very specific list, but i figured that some of you would have some ready made scripts that we can adapt etc.

I am interested in ANY scripts that you find useful for your sysadmin tasks in unix/linux.

Plus any sites that you know of that has such scripts would be great?

Thanks.
 
Also interested in this - i'd like something to watch a particular folder, and drop me a daily email with the sizes of the sub folders within.

Matt :)
 
the last one with syslog, never done any "real" scripting something likke this may work?

tail -f | grep -irh "error" | mail [email protected]

if error never comes up in syslog the you could creat a text file with words to look for and tell grep to use the text file as input.

I'm sure some one will come along and improve ( would take much ) on the above probably using perl.

It's a start at least.

Cheers
Deano
 
and one for checking disk space in general not 90% +

#!/bin/sh

DISC=$1
PARTITION=`df -h |grep $DISC |awk '{print $1}'`
SIZE=`df -h|grep $DISC|awk '{print $2}'`
USED=`df -h|grep $DISC|awk '{print $3}'`
FREE=`df -h|grep $DISC|awk '{print $4}'`

echo "Partition: $PARTITION"
echo "Total size: $SIZE"
echo "Used space: $USED"
echo "Free space: $FREE"

save it as say info.sh then to check disk space do at promt info.sh hda3

taken from

http://forevergeek.com/linux/check_disk_space_in_linux.php

cheers
Deano
 
You could do it in bash, but it might be a bit messy and require some creative regexps (for 90% +)

I recon using perl or python might be a bit more sensible, and are likely to have handy libraries to help.
 
i've literally done the same as you, but I did it in java cause I was bored :)

bit useless at bash scripting me
 
feenster99 said:
Also interested in this - i'd like something to watch a particular folder, and drop me a daily email with the sizes of the sub folders within.

Matt :)

Well... I can do this one myself :)

How about...

#!/bin/sh
echo "Subject: dirsize email" > dirsize.tmp
du -ks $1 >> dirsize.tmp
du -ks $1/* >> dirsize.tmp
cat dirsize.tmp | mail $2
rm -f dirsize.tmp

Save it as a script called dirsize.sh and chmod u+x it. Then just stick it in your crontab or use it at command line like follows...

./dirsize.sh /home/blahsdir/ [email protected]

Cheers.
 
Back
Top Bottom