h1

configure a new email cron job in Solaris 10

March 23, 2009

I needed to configure a new cron job in Solaris 10 which runs a shell script and then emails the results of the script to a few email addresses. The task contained 2 parts:

  1. Configuring email on Solaris 10: we have an SMTP server already configured. All I had to do was open /etc/main/submit.cf (first back it up) and then edit the line which reads:
  2.             D{MTAHost}[127.0.0.1]

                 to

                D{MTAHost}[SMTP_HOST_NAME]

                Restart sendmail by issing the commands: /etc/init.d/sendmail stop and /etc/init.d/sendmail start

  3. Configure crontab: First of all you need to make sure that you can run cron jobs.  Go to /usr/lib/cron (assuming you have root privileges) and open the file cron.allow (assuming it exists). If your name appears in the list, you can add cron jobs. If not just add your UNIX username. If this file does not exist, see if cron.deny exists. If this exists and your name is not in there, then you can use crontab. If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line. 

Edit your crontab file by:

export EDITOR=vi ;to specify a editor to open crontab file.

crontab -e     Edit your crontab file, or create one if it doesn’t already exist.

crontab -l      Display your crontab file.

crontab -r      Remove your crontab file.

crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.) 

 

A line in crontab file like below  removes the tmp files from /home/someuser/tmp each day at 6:30 PM.

30     18     *     *     *         rm /home/someuser/tmp/*

Leave a Comment