怎样在unix/linux下添加批处理作业

 
Cron job are used to schedule commands to be executed periodically i.e. to setup commands which will repeatedly run at a set time, you can use the cron jobs.

crontab is the command used to install, deinstall or list the tables used to drive the cron daemon in Vixie Cron. Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to use crontab command for editing or setting up your own cron jobs.

To edit your crontab file, type the following command:

$ crontab -e

Syntax of crontab
Your cron job looks like as follows:

1 2 3 4 5 /path/to/command arg1 arg2

Where,

  • 1: Minute (0-59)
  • 2: Hours (0-23)
  • 3: Day (0-31)
  • 4: Month (0-12 [12 == December])
  • 5: Day of the week(0-7 [7 or 0 == sunday])
  • /path/to/command - Script or command name to schedule

Same above five fields structure can be easily remembered with following diagram:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Example(s)
If you wished to have a script named /root/backup.sh run every day at 3am, my crontab entry would look like as follows:
(a) Install your cronjob:

# crontab -e

(b)Append following entry:

0 3 * * * /root/backup.sh

Run five minutes after midnight, every day:

5 0 * * * /path/to/command

Run at 2:15pm on the first of every month:

15 14 1 * * /path/to/command

Run at 10 pm on weekdays:

0 22 * * 1-5 /path/to/command

Run 23 minutes after midnigbt, 2am, 4am ..., everyday:

23 0-23/2 * * * /path/to/command

Run at 5 after 4 every sunday:

5 4 * * sun /path/to/command

Use of operators
An operator allows you to specifying multiple values in a field. There are three operators:

  1. The asterisk (*) : This operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.
  2. The comma (,) : This operator specifies a list of values, for example: "1,5,10,15,20, 25".
  3. The dash (-) : This operator specifies a range of values, for example: "5-15" days , which is equivalent to typing "5,6,7,8,9,…,13,14,15" using the comma operator.

How do I disabling Email output?
By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1. For example:

0 3 * * * /root/backup.sh >/dev/null 2>&1

To mail output to particluer email account let us say vivek@nixcraft.in you need to define MAILTO variable to your cron job:

MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1

To list your crontab jobs use the command:

# crontab -l

To remove or erase all crontab jobs use the command:

# crontab -e

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux 下使用! PBS是一个批处理作业和计算机系统资源管理软件包。它原本是按照POSIX 1003.2d批处理环境来开发的。这样,它就可以接受批处理作业、shell脚本和控制属性,作业运行前对其储存并保护,然后运行作业,并且把输出转发回提交者。   PBS可以被安装并配置运行在单机系统或多个系统组来支持作业处理。由于PBS的灵活性,多个系统可以以多种方式组合。 PBS的组件   PBS包括四个主要的组件:命令组件、作业服务器、作业执行组件和作业调度器。这里给出每一部分的简要描述来帮助你在安装过程中做出决定。   命令组件:   PBS支持与POSIX1003.2d相一致的命令行和图形接口两种命令方式。这些命令用于提交、监视、修改和删除作业。命令可以被安装在任何PBS支持的系统类型上,并且不需要在本地安装任何其它的PBS组件。共有三种类型的命令:任何已授权用户可以使用的命令;操作员命令;管理员命令;操作员和管理员命令需要不同的访问权限。   作业服务器:   作业服务器是PBS的中心。在本文档中,它一般被称作服务器或被称为可执行文件的名字pbs_server。所有命令和其它守护进程都通过IP网络和服务器通信。服务器的主要功能就是提供基本的批处理服务,例如接收/创建一个批处理作业,修改作业,保护作业免受系统宕机的影响并运行作业。   作业执行器:   作业执行器是一个守护进程,它真正地把作业放入执行队列。这一进程,pbs_mon,被非正式地命名为Mom,正如它是所有正在执行的作业的母亲(mother)一样。当Mom从一个服务器那里接收一个作业拷贝时就将它放入执行队列。Mom创建一个和用户登陆会话尽可能一致的新的会话。例如,如果用户的登陆shell是csh,那么Mom就创建一个会话,在此会话中.login和.cshrc一样运行。当服务器指示需要那么做时,Mom也负责把作业的输出返回给用户。   作业调度器:   作业调度器是另一个守护进程,这一进程包括site’ policy[1],这一策略控制着哪一个作业被运行,在那个节点运行,什么时候运行。因为每一个site对于什么是好的或者有效的策略都有它自己的想法,PBS允许每一个site来创建它自己的调度器。当运行的时候,调度器就可以和不同的Moms进行通信来获知系统资源的状态;和服务器进行通信来获知要执行的作业的有效性。与服务器之间的接口是通过和命令组件一样的API。实际上,调度器仅仅作为服务器的批处理管理器出现的。   除了上面主要的部分之外,PBS也提供了一个应用编程接口,API,命令组件用它来和服务器进行通信。这一API在和PBS一起完成的第三部分的man pages中描述。A site[1]如果愿意可以利用这些API来实现新的命令。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值