Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP! BEGINNER BASH SCRIPT! 1

Status
Not open for further replies.

beacon

MIS
Oct 23, 2001
5
US
Hi all,

I need a bash script to do the following:

A list of currently running proccess's owned by root!
Amount of time the machine has been up and load average
List of all used and unused space on OS partition
List of all users online(on machine)
Also if the HD space is below 5% then email send an email to a specified email address or default with date, and username of person who executed this script!

Then it needs to put all of this into an email and email to an inputted email address and if not entered email to a defualt email address.

Anyone give me any idea of what to do? PLEASE
 
1 - Check out the ps command, look at the -u option.

2 - Check out the uptime command.

3 - Check out the df command.

4 - Check out the who command.

5 - df command, again.

That should give you a start, but please try to do a bit of research before you just post what looks like a college assignment. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks.
Nope dont go to college or uni or anything!

A workmate asked me to see if i could do the following and since i have no clue whatsoever about script writing i thought i would ask.

 
Also

Have a look at the manual pages for cron and crontab, which explain how you can schedule autmated processes to occur at specific times / intervals.

Cheers, NEIL
 
Ok, fair enough.

Get back to us when you've had a chance to look at the documentation suggested by myself and Neil

Regards,
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
hey guys,

Been struggling through it for 2 days now!
Getting better at it!

The only 2 things i'm stuck on is these i would appreciate any help!:

1) If the HD space is below 5% then send an email to a specified email address or default address.

I dont know how to check last below 5%.

2) This is formatting question. How can i remove certain columns?
Like using the df command i only want size, Used, Available and Capacity%!

Is this possible???

Thanks for any help :)
 
Hi,

well, it depends on your configuration, but for most installations you will have to check the partions (logical volumes or whatever) with df or bdf (HP-UX).

bdf
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 204800 61205 134727 31% /
so you can see the used space and create an email if necessary.

For formating, check manpage of "cut"

good luck

rapace

 
Awk would probably suit your formatting needs better. Sorry, I'm no expert, but there are those out there who are...
 
OK, having RTFM, the following should give you an idea:

cat your df output into a file:

df -k > dflist

Examine the file for the columns you require:

pg dflist (column numbers start at 1)

Pass the file through awk to return only those columns required:

eg awk '{ print $1, $3, $5 }' dflist

This is a little quick and dirty and could do with some additional formatting, but it should get you started.
 
this should work on solaris
df -k | egrep -v &quot;capacity|cdrom| 0%&quot; | awk '$4/$2 < 0.5 { print $1,$2,$3,$4,$5}'

Ged Jones

Top man
 
Someone posted this on one of the Unix forums a while back. This one lists the usage on all file systems, and shows a warning if any of the systems are using more than 86%
Code:
clear
echo &quot;                          Checking File Systems&quot;
echo
echo &quot;Mount                Total        Used       Free       Used%     Test&quot;
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
df -k |grep /| awk '{$2 = $2 /1000;  $3 = $3 /1000 ; {if ($5>86 || $5==&quot;100%&quot;) $
9 = &quot;warning&quot;}; $4 = $4 /1000; printf &quot;%-15s &quot;          &quot;%8.1f Mb  &quot;          &quot;%
8.1f Mb&quot; &quot;%8.1f Mb\t%5s%10s\n&quot; ,$6, $2, $3,$4,$5,$9}'|sort
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo
echo &quot;Check file systems with warning&quot;
echo
This may appear complicated to the beginner, but if you figure it out you're halfway there!

Greg.
 
hey all again,

Still a little slow i guess!

They all work but getting it to send the email if below %5 is hard!!

Greg that script is good but how can i remove the last column test and add in send to blah@blah.com. It gives me invalid character @??

any ideas.
I thank you all for your help!
 
Hi beacon,

Replace the word sort with

grep warning | mailx -s 'less than 5pc free' blah@blah.com Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
thanks mike and everyone!
Much appreciated!
I'm on my way! yipee!
:D
:D
 
<grin> the easy fixes are my favorites.... Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top