Count the size and send notification


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count the size and send notification
# 1  
Count the size and send notification

Hello,

I want to do something simple,

I want to count the dir size (du -sh directoryname) and then check if
it is over 100GB.
If it is more than 100GB I want to send a notification , if it less than 100GB the script can just stop.

I know how to count with du -sh and how to send an email but I dont know how to compare with 100GB, any help?

thank you.
# 2  
Hi,

don't use -h option, it show you in human readable
# 3  
thank you for the tip pokerino,
but how do I say "if its more than $ then do this" ?
# 4  
try and modify this:
Quote:
#!/bin/bash

for a in "$(du -s $1)"
do
spc=$(echo $a|cut -d" " -f1)
if [ $spc -gt 100000 ]
then
echo "alert on $1, the space is $spc"|mail wyw@wyw.world -s "Alert space"
fi
done
pass a directory as argument.
adjust the max value when needed
# 5  
to get the file size in number(GB)
Code:
stat -c %s infile | awk '{print $1/(1024**3)}'

# 6  
The output from du -sk is in 1024 byte blocks.

100 Gb = (100 x 1024 x 1024 x 1024) bytes
Which is the same as (100 x 1024 x 1024) blocks of size 1024 bytes. i.e. 104857600 1024-byte blocks.

Code:
dir="directoryname"
blocks=$(du -sk "${dir}" | awk '{print $1')
if [ $blocks -gt 104857600 ]
then
       echo "Directory larger than 100 Mb: ${dir}"
fi

@pokerino Your units are incorrect.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #835
Difficulty: Medium
SOAPjr is a protocol specification for exchanging structured information in the implementation of web services in computer networks.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to monitor some UNIX process and send notification in every 10 minutes?

Hi Unix Members, Can anyone guide me to write one shell script to monitor the attach screen processes and when interrupted mail us. , like the processes - /bin/ciserver , /bin/clock , /bin/cserver , /bin/main Please looking forward you guys help. (6 Replies)
Discussion started by: biswajitnitd
6 Replies

2. Shell Programming and Scripting

Script to send email if count is >1

i have below code to count number of rows in file1.txt, if the row count is more than one then i have sending an email along with file1.txt attached and fail the process(do nothing if count is <=1), if I test individually count part works good but when i include the email part its not working,... (4 Replies)
Discussion started by: srini_106
4 Replies

3. Shell Programming and Scripting

Send email based on row count

i have below code to count number of rows in file1.txt, if the row count is more than one then i have sending an email along with file1.txt attached and fail the process(do nothing if count is <=1), if I test individually count part works good but when i include the email part its not working,... (1 Reply)
Discussion started by: srini_106
1 Replies

4. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

5. Shell Programming and Scripting

Script for count files and send mails

Hi. I'm new on this forum and I need if possible someone to help me with one script. The script should act like this: - should be run by crontab and have next parameters: script_name $par1 $par2 $par3 $par4 where script will search in dir $par1 for files with mask $par2 and if number of... (2 Replies)
Discussion started by: atrailm
2 Replies

6. UNIX for Advanced & Expert Users

Zip the files if count is more than 0 and send a mail

All, I am new to shell scripting and trying to get the count of files that starts with error and with extension .out, if the count is greater than 0 and zip the file and send an email with the content of error.out file, here is my script cd /temp testcount =$('find . -name '*.out' -print |... (4 Replies)
Discussion started by: luckydoll
4 Replies

7. Shell Programming and Scripting

check postfix deferred mail and send notification script

Hi Guys, I have a postfix server which is deferring emails. Now I need to send notification to a specific email address if: The sender of the deferred email is: abc@example.com Contains specific subjects: a file (/opt/subjects) contains all the subjects in place Then need to send a... (0 Replies)
Discussion started by: linuxrulz
0 Replies

8. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

9. Shell Programming and Scripting

How to read specific line of text from a Script and send email notification

Hi ! I am a newbie and never officially wrote a shell script before. The requirement for this script is : 1) Read a file called 'bpm.log' and identify if it has a specific text such as 'this is the text'. Its a static value and that is the only text we need to read. 2) If that... (2 Replies)
Discussion started by: atechcorp
2 Replies

10. UNIX for Dummies Questions & Answers

Counting Files and send an email Notification if it exceeds a limit

Hi, I am trying to write a script to Count Files in a directory located on a remote server and send an email Notification if it exceeds a limit. The code given below doesnot check the condition and sends the mail everytime irrespective of the condition. I have put this script in the cron. Can... (10 Replies)
Discussion started by: amitsayshii
10 Replies

Featured Tech Videos