Link to home
Start Free TrialLog in
Avatar of V Thrusher
V Thrusher

asked on

need a shell script to send disk usage report everyday

need a shell script to send disk usage report everyday about the filesystem
Avatar of serialband
serialband
Flag of Ukraine image

Create a cron entry and run the mail command to send the output of df or du

00 15 * * * mailx -s `df -h` me@example.org
00 16 * * * mailx -s `du -h /home/*` me@example.org

Open in new window

Avatar of V Thrusher
V Thrusher

ASKER

Is there a way to make the data a more re presentable format ?
Rather than use the output of the command as the subject, use standard input for the mail body:
0 15 * * * df -h | mailx -s "Disk usage" me@example.org

Open in new window

What kind of output format do you prefer?

Currently,
> df -hl
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             249G  164G   73G  70% /

Or you just want "Mount point" and "Use%", then
> df -hl | awk '{print $6,"\t", $5}'
Mounted        Use%
/                        70%

To set up a cron job, run
> crontab -e
and edit
0 0 * * * /bin/df -hl | /bin/awk '{print $6,"\t", $5}' | mailx -s "Disk Usage" <email address>

It will send you the email with subject "Disk Usage" at 12:00AM everyday.
The cron line is getting quite long - the limit was (and probably still is) quite low, so you might want to put the commands in a script file, and just call that script from cron.
i need my script to be in re-presentable format and should have disk usage diff from last time checking
ASKER CERTIFIED SOLUTION
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial