![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 ~ |
|
#3
|
|||
|
|||
|
@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
|
|
#4
|
|||
|
|||
|
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?( Anyway, hope it works for him. Thanks, Praveen Indramohan |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
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> !!! |
|||
| Google The UNIX and Linux Forums |
| Tags |
| linux, ubuntu |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|