Script for Monitoring Root Filesystem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script for Monitoring Root Filesystem
# 1  
Old 04-14-2014
Script for Monitoring Root Filesystem

I am on SCO UNIX, I need to write a script to monitor root file system. For some reason it's not working for me.

Code:
 
#!/bin/sh
df -B / | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
if [ $output -ge 85 ]; then
    echo "Running out of space \ HOSTNAME"
#     mail -s "Alert: Almost out of disk space root file system" USER_email
fi
done

when I run this...


Code:
./check*
Capacity Filesystem
./check.sh: test: unknown operator Filesystem

# 2  
Old 04-14-2014
In the below code, you are reading output as col5 and col1 joined with space
Code:
df -B / | awk '{ print $5 " " $1 }' | while read output;

In that case, how can you compare '$output' with a number
Code:
if [ $output -ge 85 ]; then

If you are sure about that, the error you got is because of if condition. use double square brackets
Code:
if [[ $output -ge 85 ]]; then

# 3  
Old 04-14-2014
Thanks for quick help, I am getting the results but still missing. How do I compare to say alert me if it's over 80%...

Code:
 
#df -B /
Filesystem          512-blocks     Used Available Capacity Mounted on
/dev/root             16421294 14270320   2150974      87% /

#./check*
Capacity Filesystem
./check.^?4filesystem.sh: [[Capacity: not found
87% /dev/root
./check.^?4filesystem.sh: [[87%: not found

# 4  
Old 04-14-2014
You have two items in your awk printout: $5 and $1. Both will be read into that output variable. Use two variables, like read percent FS, remove the percent sign from the first variable (either in awk or with shell parameter expansion), and don't process line 1.
One possible solution:
Code:
awk 'NR>1 {sub("%", "", $5); print $5 " " $1 }'

# 5  
Old 04-15-2014
Here is the updated script. I am still getting syntax error. Some one help me please?
Code:
 
 
#!/bin/sh
df -B /  | awk '{ print $5 " " $1 }' | while read output;
do
  echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  ) partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge 90 ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space on $(hostname)" group_email
  fi
done

when I run it, I get this err.msg.
Code:
#./check2.sh
./check2.sh: syntax error at line 5: `usep=$' unexpected

---------- Post updated 04-15-14 at 11:15 AM ---------- Previous update was 04-14-14 at 07:27 PM ----------

Can any one help me with the above syntax error ? Thank you so much.
# 6  
Old 04-15-2014
Are you sure about the -B option of df?
Because for the rest I see not reason for an issue and I have no SCO anymore to check the man pages about -B ... Unless you have a very basic sh... try using ksh, if it works, then its your sh that doesnt like the format
Code:
VAL=$( do something to get value)

and so needs to be replaced by
Code:
VAL=`execute blah blah `


Last edited by vbe; 04-15-2014 at 01:56 PM.. Reason: added the replacement syntax
# 7  
Old 04-15-2014
Does this help?

Code:
ALERT_VALUE=85
output="$(df /|grep -v block)"
VALUE=$(echo "$output"|awk '{print $5}'|sed s/\%//g)
partition=$(echo "$output"|awk '{print $1}')
if [ $VALUE -ge $ALERT_VALUE ]
then 	echo "Running out of space \"$partition ($VALUE%)\" on $(hostname) as on $(date)" |
	mail -s "Alert: Almost out of disk space on $(hostname)" group_email
fi

Or your way:
Code:
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  ) partition=$(echo $output | awk '{ print $2 }' )

Should be either:
Code:
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  ) 
partition=$(echo $output | awk '{ print $2 }' )

OR
Code:
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  ) ; partition=$(echo $output | awk '{ print $2 }' )

hth

Last edited by sea; 04-15-2014 at 04:22 PM.. Reason: Added missing code segment and typo
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Filesystem getting full. Need a monitoring script

Hi, I am new to shell scripting in unix HP-UX. I need to determine how much a perticular file system is full and if it goes over 80% it should notify through mail about which are the files which are greater than 1 GB size. I used df -k command it is showing the alloocated KB and the %used... (14 Replies)
Discussion started by: Soma Das
14 Replies

2. AIX

Performance Monitoring of FileSystem

As I am new to the Unix field, I would like to get the clarification regarding the Filesystem. The scenario is.. The filesystem (/drbackup) is getting monitored and if it exceeds the threshold, we will receive an alert from it. The issue is that we receive an alert with the description of... (2 Replies)
Discussion started by: A.Srenivasan
2 Replies

3. UNIX for Dummies Questions & Answers

Root filesystem filling up!

Hi all. New to the forum and new to Unix admin... / filesystem filled up and I can't find where the large files are. Any help will be apppreciated: # df -k Filesystem kbytes used avail capacity Mounted on /dev/dsk/c1t0d0s0 8063580 7941745 41200 100% / /proc ... (4 Replies)
Discussion started by: jamie_collins
4 Replies

4. Shell Programming and Scripting

Monitoring Script - filesystem

Hi all, I got an error when running this script (from BigAdmin community) the error is test: argument expected my server version is SunOS XXX 5.8 Generic_117350-46 sun4u sparc SUNW,Sun-Fire-V890 any idea on it? #! /usr/bin/ksh ### ### This script can be run from cron to... (9 Replies)
Discussion started by: SmartAntz
9 Replies

5. AIX

Help with a filesystem monitoring script.

I'd like to create a cron script that checks filesystems. For example if it reaches 95% USED, I'd like it to send me an email. Can this be possible for up to say 4 filesystems using the df -k command? Any samples to get me started would be much appreciated. (7 Replies)
Discussion started by: NycUnxer
7 Replies

6. Solaris

Root Filesystem

Hi, Can we install root file system on other than 0th slice???? (5 Replies)
Discussion started by: tirupathiraju_t
5 Replies

7. Shell Programming and Scripting

Filesystem Monitoring script problems

Hi there all, #!/usr/bin/ksh Set -x MIN_MB_FREE="100MB" # Min. MB of Free FS Space MAX_PERCENT="85%" # Max. FS percentage value FSTRIGGER="1000MB" # Trigger to switch from % Used to MB Free WORKFILE="/tmp/df.work" # Holds filesystem data >$WORKFILE #... (0 Replies)
Discussion started by: draco
0 Replies

8. Shell Programming and Scripting

Script for Deleting Core files on root filesystem

ok i am setting up a script to run daily using crontab. This script will search the root filesystem and delete any and all core files. I have set up this script The only problem i get with this script is it searches for directories and attempts to delete them. Since i have probably... (7 Replies)
Discussion started by: rgfirefly24
7 Replies

9. UNIX for Advanced & Expert Users

Mounted Root Filesystem

In my Solaris 10 based server, I have noticed the following mounts when a use DF -K /dev/dsk/c0t0d0s0 5062414 3213876 1797914 65% / / 5062414 3213876 1797914 65% /net/se420 I understand the first mount because it appears in my vfstab file and is the mount of root that I would expect.... (1 Reply)
Discussion started by: jimthompson
1 Replies

10. Linux

Monitoring of Root

Hi, I am trying to monitor the login of root on my Red Hat linux box. Is there a audit trail for this on the system? Thanxs. Kayode (1 Reply)
Discussion started by: kayode
1 Replies
Login or Register to Ask a Question