I am in the need of a script which can send the mail for every 'n' minutes automatically through the shell script? How to do it?
#!/bin/sh mail -s "Hi, it's me again" user@host <<'END_MAIL' Hi, Just wanted to say I'm still here. Don't forget to feed the cat. Regards, Me END_EMAIL
10 * * * * /path/to/script.sh
You would write the script, which in this case is really just one single command that sends an email with a particular subject line and contents to someone, make it executable with
chmod +x script.sh and put it somewhere, e.g. in you home directory.
In the message body (which is given as a here-document in the script above), if you need to have variables or command substitutions expanded by the shell, then change
END_EMAIL (i.e. remove the quotes). Note that this means that any
$ that you don't want the shell to treat as the beginning of an expansion must be escaped as
\$ in this case.
The cron schedule would be added by using
crontab -e and typing in the single line above. Saving that and exiting the editor would enable the schedule and it would call your script every 10 minutes.
You should read
man 5 crontab) for how to format crontab schedules.
Would you want to change the contents, subject or receiver of the email, edit the script. Would you want to change the schedule, change the crontab using