向Solaris系统添加cron job

原创 2007年09月20日 08:53:00
cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris.

Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.


1. Crontab Restrictions
____________
You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use
crontab if your name does not appear in the file /usr/lib/cron/cron.deny.
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.


2. Crontab Commands
__________
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.)
 

3. Crontab file
___________
Crontab syntax :-
A crontab file has five fields for specifying day , date and time  followed by the command to be run at that interval.

*     *   *   *    *  command to be executed
-     -    -    -    -
|     |     |     |     |
|     |     |     |     +----- day of week (0 - 6) (Sunday=0)
|     |     |     +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
 

* in the value field above means all legal values as in braces for that column.
The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).

Note: The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .

4. Crontab Example
_______

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/*

 

Changing the parameter values as below will cause this command to run at different time schedule below :

min hour day/month month day/week  Execution time
30 0 1 1,6,12 * -- 00:30 Hrs  on 1st of Jan, June & Dec.

:

0 20 * 10 1-5 --8.00 PM every weekday (Mon-Fri) only in Oct.

:

0 0 1,10,15 * * -- midnight on 1st ,10th & 15th of month

:

5,10 0 10 * 1 -- At 12.05,12.10 every Monday & on 10th of every month
:

Note : If you inadvertently enter the crontab command with no argument(s), do not attempt to get out with Control-d. This removes all entries in your crontab file. Instead, exit with Control-c.

5. Crontab Environment
___________
cron invokes the command from the user's HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.

6. Disable Email
____________

By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .

>/dev/null 2>&1


7. Generate log file
________________

To collect the cron execution execution log in a file :

30 18  *    *   *    rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log

8. Next Steps

This  article  covered  a significant aspect of system administration of setting up cronjobs . Unix administration involves lots of different tasks and some of these tasks are covered in this website  but still there are many areas not covered here .

Following books available for online buying from Amazon.com . You should have following two books in your bookshelf  for ready reference  if you are involved in Unix system administration  . 

Essential System Administration, Third Edition by by Æleen Frisch
Solaris Operating Environment Boot Camp by David Rhodes, Dominic Butler

If you already own these books the amazon display panel below shows some of the best-selling books for System Administration  and you can choose the book here or visit my other website for more selection of best selling unix system administration books by following this link - .Unix system administration books at besttechbooks.com ,from Amazon.com.

 

Solaris系统cron服务异常解决记录

自从公司政策变化,将服务器转到部门后,像我这种小白总会遇到各种各样维护的问题,这不,最近两月发现NIS服务工作异常,不能实时同步远端LDAP数据了。由于NIS和DNS服务器系统是古老的SunOS 5....
  • guyongqiangx
  • guyongqiangx
  • 2017年08月25日 20:51
  • 488

向Solaris系统添加cron job

cron is a unix, solaris utility that allows tasks to be automatically run in the background at re...
  • hotsolaris
  • hotsolaris
  • 2007年09月20日 08:53
  • 3616

Solaris的crontab

1.crontab环境介绍1.    cron服务在/etc/init.d/cron2.    执行文件/usr/sbin/cron3.    cron配置文件在/etc/cron.dfile lis...
  • sipsir
  • sipsir
  • 2008年04月10日 17:41
  • 15938

CronJob简介

转自:http://blog.sina.com.cn/s/blog_53f716d40100hlv2.html Cron 是UNIX,SOLARIS,LINUX下的一个十分有用的工具。通过Cron脚...
  • hj402555749
  • hj402555749
  • 2012年07月17日 10:50
  • 10448

Linux CronJob简介

Cron 是UNIX,SOLARIS,LINUX下的一个十分有用的工具。通过Cron脚本能使计划任务定期地在系统后台自动运行。这种计划任务在UNIX,SOLARIS, LINUX下术语为cron jo...
  • yockie
  • yockie
  • 2016年04月11日 14:25
  • 1229

Solaris10 cron使用

 
  • jaytse
  • jaytse
  • 2008年07月25日 16:11
  • 1739

Linux下cron服务

实现linux定时任务有:cron、anacron、at等,这里主要介绍cron服务。 名词解释:    cron是服务名称,crond是后台进程,crontab则是定制好的计划任务表。 软件包安装...
  • payton_liu
  • payton_liu
  • 2013年12月04日 15:53
  • 1116

magento -- 计划任务(cron job)在magento中的作用和使用教程

      计划任务(cron job)是Magento系统中一个很有用甚至可以说必须使用的功能,而最近在网上跟人聊天发现很多Magento的使用者不知道这个功能或者知道却认为可有可无,我在这里建议各...
  • shuishui8310
  • shuishui8310
  • 2010年05月08日 23:15
  • 15387

Solaris10 为用户添加定时任务(crontab)

1. 检查一下cron服务是否已启动root@ocs00biiitf001:~ #> svcs | grep crononline         15:11:29 svc:/system/cron:...
  • gyd1
  • gyd1
  • 2010年06月27日 11:18
  • 1085

Solaris 下 Crontab 用法详解

solaris下crontab的使用和linux都有些区别 开始#bash后 首先得定义系统环境变量EDITOR # export EDITOR=vi 然后再开始编辑 ...
  • xiangsir
  • xiangsir
  • 2013年02月05日 01:10
  • 2105
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:向Solaris系统添加cron job
举报原因:
原因补充:

(最多只允许输入30个字)