Writing a cron job to email myself

1

2

How would i write a simple cron job to email myself a message at a certain time? Also is it possible to create a cron job without root access. I'm trying to use my school's server?

Sean

Posted 2012-02-19T06:35:39.220

Reputation: 171

issue "crontab -e" to check if you even have the ability to schedule a cron task. You can look for the /etc/cron.* directories, but I doubt they are open for you to add anything. – tawman – 2012-02-19T07:09:32.720

Answers

3

Check if your name appears in the file /etc/cron.allow

If your name is not listed in /etc/cron.allow, you can use crontab if not listed in /etc/cron.deny. If neither file exists, unfortunately only the root user can use crontab.

You can put a job in crotab with crontab -e option following the pattern bellow.

*     *     *   *    *        /path/to/script.sh
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

Create a simple like the sample bellow to send you the mail:

#!/bin/sh
 EMAILID="your@email"
 MAIL=/tmp/mail.$$
 echo "Line 1">$MAIL
 echo "Line 2" >>$MAIL
 echo "Line 3" >>$MAIL
 ...
 mail  -s "Subject" "$EMAILID" <$MAIL
 rm -f $MAIL

Franks Maia

Posted 2012-02-19T06:35:39.220

Reputation:

1

Any cheapest hosted solution will give you a cron job manager, even if you do not have a root access.

If not a cron, you can always do a simple script that wakes after certain time, and email you

for(;;){
  email();
  sleep(60);
}

jeff musk

Posted 2012-02-19T06:35:39.220

Reputation: 111