The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix script to check whether particular file exists and to find its size Balachandar Shell Programming and Scripting 9 02-05-2008 12:56 AM
compare file size from a output file from a script moustik Shell Programming and Scripting 7 11-07-2007 07:17 AM
Shell script to Find file size ragsnovel Shell Programming and Scripting 1 08-10-2007 07:01 AM
Get file size in c shell script? Dado Shell Programming and Scripting 6 09-26-2005 01:48 AM
testing for file size in script Ivo UNIX for Dummies Questions & Answers 3 03-13-2002 11:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-14-2006
Registered User
 

Join Date: Aug 2006
Posts: 20
file size script

Hi, I am trying to write a script that will send an email to me if the size of a folder is below a certain amount.

Does anyone know how to write the if (size < 1000) statement. I know how to send the email? I just need the code for determing a folder size.

Thanks,
Eric
Reply With Quote
Forum Sponsor
  #2  
Old 09-14-2006
Registered User
 

Join Date: Sep 2006
Posts: 10
Hi,

Try this:

#!/bin/sh

SIZE=`ls -ltr FILENAME|awk '{print $5}'`

if [ $SIZE -ge 700 ] ##say..size exceeds 700

then

echo "FILE SIZE EXCEEDED!!"

else

echo "FILE SIZE OK"

fi


## Hope this helps,

## Praveen Indramohan
~
Reply With Quote
  #3  
Old 09-14-2006
Registered User
 

Join Date: Aug 2006
Posts: 30
Lightbulb

@praveen : i think u got it a bit wrong.he said he wanted to be informed by an email...

the following code will work(hoping u have a mailing client installed in ur OS)
Code:
#!/bin/sh
SIZE=`du -s FOLDERNAME |awk '{print $1}'`
if [ $SIZE -le 1000 ] 
then
echo -e "FOLDER SIZE LESS THAN 1000 !!\n Folder size=$SIZE" | mail -s "Folder size notification" emailid@hostname.com
fi
hope this works.....
Reply With Quote
  #4  
Old 09-15-2006
Registered User
 

Join Date: Sep 2006
Posts: 10
yeah, may be,

but he said : "I just need the code for determing a folder size."

and he said : i know how to send email?( why the question mark?)

Anyway, hope it works for him.

Thanks,

Praveen Indramohan
Reply With Quote
  #5  
Old 09-15-2006
Registered User
 

Join Date: Aug 2006
Posts: 20
Hi, I am using exact code from sayonm. I get the error though that:

line 2: }: command not found
line 3: [: -le: unary command expected

Anyone know how to fix these two errors. I am assuming by unary it just means to use <, >, =, etc.

As for the first error, it seems like it doesn't know the print command. I am using Ubuntu, if that helps.

Thanks,
Eric
Reply With Quote
  #6  
Old 09-17-2006
Registered User
 

Join Date: May 2006
Posts: 101
please,
try this SIZE calculation, it does not need awk and removes those backticks.
advantage 2, you can define the directory as cmd line argument else the current directore is counted.
btw: do not forget to chmod +x the script !

SIZE=$( du -s $1 | expand | cut -d\ -f1 ) # note cut -d\<space><space> !!!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux, ubuntu

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0