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?

  • This question is being down voted because you did not gave details about it – intika May 6 at 10:31
  • Yes, I've just given a down-vote because of single-line "explanation" of the problem. Do make some effort the next time asking our help please. – LinuxSecurityFreak May 6 at 10:33

Short script:


mail -s "Hi, it's me again" user@host <<'END_MAIL'

Just wanted to say I'm still here.
Don't forget to feed the cat.


Cron schedule:

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' to 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 crontab(5) (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 crontab -e.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.