I need help in creating a script that will run once a day in afternoon and collect the information of each partition(Disk Space , Total and Used) and send it to my email.
Please help im very very new in this scripting thing.
|
I need help in creating a script that will run once a day in afternoon and collect the information of each partition(Disk Space , Total and Used) and send it to my email. Please help im very very new in this scripting thing. |
|||
|
|
|
Provided you have an MTA configured on that machine to accept and relay mail for you (on a server that should be the case) try this:
(MTA = Postfix, Exim, etc.)
If that fits your needs, add it to your crontab to run every day:
An editor will open. Add a line like this:
Save and close. This will make it run with the other daily tasks. If you need a report on a specific time of the day or error logging to a specific address, please read about the cron syntax (a lot of this is on the Internet - here's one random website). For example:
In case you can't send out mail on that machine directly, read this or the answer by @hakermania on how to do that (many more ways exist). |
|||||||||
|
|
In order to make the script running you will need to setup a cron job with it: How do I setup a cronjob ? Now, inside your script, you will need to do something like this:
As you can see, I'm calling a python script from within your root path (not readable but nobody else but root himself) which takes the following arguments: "recipient-email" "title-of-email" "body-of-email" "attachment" This python script is this:
Of course you will need to provide it with your gmail email and password at the top of the script ( So, summing up, you will need to setup a cron job with the above bash script. This bash script will save the output of PS: The above solution will show the free and total disk space only of your mounted filesystems. If this is a problem please inform me so as to extend my answer about how to automatically mount all the available filesystems and then run |
|||||
|
|
You can use this script to check the disk usage
Use |
||||
|
|