Space Clean Up Activity In Unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Space Clean Up Activity In Unix
# 1  
Old 01-18-2007
Space Clean Up Activity In Unix

Hi

I am trying to develop a script so that whenever used % reaches 90% it will send an alert mail. Following is the script whic I am tryiing to implement but it show some error.

code:
#! /bin/ksh
df -v | grep -i "/opt" | awk '{print $6}' > space
if [[ $space -ge "90%" ]]
then
echo "ALERT YOUR SPACE IS TOO LESS ...PLEASE SEND MAIL TO CM GROUP"
mailx -s "[`date`] ALERT :CRITICAL SPACE ISSUE " xyz@gmail.com
else
echo " SPACE IS UNDER CONTROL "
fi

Error that I am recieving is as follows :

$ ./space_test.sh
./space_test.sh[3]: 90%: more tokens expected


please set my code correct

Regards
Pankaj
# 2  
Old 01-18-2007
Here is a try
Code:
opt=`bdf |grep -i /opt | awk '{print $5}' | sed 's/.$//'`
if [ $opt -ge 90 ]
then
        echo "ALERT YOUR SPACE IS TOO LESS ...PLEASE SEND MAIL TO..."
        #You send mail here
else
        echo " SPACE IS UNDER TIGHT CONTROL ;) "
fi

# 3  
Old 01-18-2007
Quote:
df -v | grep -i "/opt" | awk '{print $6}' > space
modify the above to

Code:
space=`df -v | grep -i "/opt" | awk '{print $6}'`

# 4  
Old 01-18-2007
Quote:
Originally Posted by pankajkrmishra
Hi

I am trying to develop a script so that whenever used % reaches 90% it will send an alert mail.
[snip]
Run in nohup Smilie

Code:
while :;do
       df -k | while read Filesystem kbytes used avail capacity Mounted; do
          case "$capacity" in
            *[0-9]%) [ "${capacity%\%}" -gt 90 ] && printf "%s:%15s%5s" \
		"$(hostname)" "$Mounted" "$capacity" | mailx -s "$(hostname): \
		Disk space alert"  your@address ;;
          esac
      done
  sleep 300
done

You may need to modify it for your system "df" output.

Last edited by radoulov; 01-18-2007 at 10:46 AM..
# 5  
Old 01-18-2007
Following error I recieve when I execute andryke code

$ ./space_test_new.sh
./space_test_new.sh[2]: bdf: not found
./space_test_new.sh[3]: test: argument expected
SPACE IS UNDER TIGHT CONTROL Smilie


Please suggest

Regards
Pankaj
# 6  
Old 01-18-2007
Panka, forget about mine and use matrix or radoulov code instead, I was just testing your script on hpux which uses a more comfortable way of displaying disk space stat, again sorry for that err
# 7  
Old 01-21-2007
You might consider using SNMP for something like this
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX Script to clean files

Hello All, I need a script that would delete files which are more than "X" number of days old, also if there can be a log file of the deleted files for reference. I am from windows background hence finding it difficult. Any help is much appreciated Regards Wert (4 Replies)
Discussion started by: wert468
4 Replies

2. Shell Programming and Scripting

Clean up UNIX mail box using script

Hi, I would like to clean up by unix mail mail box thru some script command.. I do know how to delete from mail box ... e.g. $ mail ? d* ? quit But I need to clean up thru some command which I can use in my script before sending any email.. Thanks in advance! (1 Reply)
Discussion started by: pareshkp
1 Replies

3. Shell Programming and Scripting

DISK SPACE in UNIX

Hi, I have to regularly monitor manually if my diskspace is close to 90% or not. I use to see this by firing df -k. I want to write a script which can run 24*7 hours and would me mail me whenever the disk space is 90% or more..It would be really great if someone can helo me on this. (1 Reply)
Discussion started by: sachin4shell
1 Replies

4. Shell Programming and Scripting

Clean up the space

Hi I just want to clean up the space in UNIX. Is there any special command that does this process or do I need to manually type the following rm <filename> Any help would be really appreciated. Thanks (2 Replies)
Discussion started by: bobby1015
2 Replies

5. Shell Programming and Scripting

monitoring various things (mainly activity) on different unix boxes

Hi there, I want to ask you guys what you think about my problem. I work as a sysadmin on about 7000 workstations or so and to save money and energy, we've decided to switch off as many workstations as possible during the night (probably by shutting it down by cron and power it on by... (8 Replies)
Discussion started by: albator1932
8 Replies

6. UNIX for Dummies Questions & Answers

how to monitor swap space paging activity?

hi guys My tivoli monitoring tools is reporting the monitor parameters says Pages Paged out is too high 1600 so it is a critical warning (threshold 400) now according to them this usually happens at dawn so is there a way to monitor this? during the time I am not working? ans something... (1 Reply)
Discussion started by: karlochacon
1 Replies

7. Shell Programming and Scripting

How to get just the word and clean the white space?

Hi, I need to check if the value returned by this query is bigger then 20000. It's not working! I think that the problem is that the return is with white spaces. How to solve this? Tks, Paulo Portugal. ####################### RESPOSTA=`/oracle/app/product/10.2/bin/sqlplus -s <<EOF / as... (2 Replies)
Discussion started by: paulofp
2 Replies

8. UNIX for Dummies Questions & Answers

SCO Unix - Disk Space

Hi, I am using SCO Unix 3.12 and Informix database. When we tried to use "du -a" command to check disk space, it showed: 342122 ./usr 30092 ./etc 6244 ./dev 4778 ./bin 2674 ./tcb 1234 ./lost+found 698 ./lib 532 ./shlib 46 ./tmp 6 ./messages 4 ./opt 4 ./var 2 ./mnt 2 ./install... (1 Reply)
Discussion started by: trinhnguyen
1 Replies

9. Programming

how to clear/clean mbufs (network buffer space)?

When I worked with client-server (socket) programming, I encountered "the socket error# 10055" which means "No buffer space available". This might be a symptom of one or more applications that didn't return system resources (like memory) properly. Temporary solution was to reboot the machine to... (7 Replies)
Discussion started by: dipti
7 Replies

10. Filesystems, Disks and Memory

Does unix ever misreport free space?

Hi all, Does unix ever misreport free space? We're having a problem running a utility, and the error message looks for all the world like the utility has no free space for its work files: HOST ERROR(D10681C). No space left on device. But the device itself shows ample free space. ... (3 Replies)
Discussion started by: JustKen
3 Replies
Login or Register to Ask a Question