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
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
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.
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.
ASKER
i need my script to be in re-presentable format and should have disk usage diff from last time checking
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window