cron- Unix, Linux Command


Advertisements

Previous Page
Next Page  
 

NAME

cron daemon to execute scheduled commands

SYNOPSIS

cron [-f] [-l][-L loglevel ] 

DESCRIPTION

cron is started automatically from /etc/init.d on entering multi-user runlevels. Cron searches its spool area (/var/spool/cron/crontabs) for crontab files (which are named after accounts in /etc/passwd); crontabs found are loaded into memory. Note that crontabs in this directory should not be accessed directly - the crontab command should be used to access and update them. Cron also reads /etc/crontab, which is in a slightly different format. Additionally, cron reads the files in /etc/cron.d.

Options

Tag Description
-f stay in foreground mode, don't daemonize.
-l Enable LSB compliant names for /etc/corn.d files. This setting, however, does not affect the parsing of files under /etc/cron.hourly, /etc/corn.daily, /etc/cron.weekly or /etc/cron.monthly .
-L loglevel Tell cron what to log about jobs as the sum of the following values:
  • 1 will log the start of all cron jobs
  • 2 will log the ends of all cron jobs
  • 4 will log all failed jobs (exit status !=0)
  • 8 will log the process number of all cron jobs
The default is to log the start of all jobs (1) .

EXAMPLES

EXAMPLE-1:

List Scheduled Cron Jobs for a particular user

# cron -u nubo -l 

output: no cron for nubo

EXAMPLE-2:

System Wide Cron Schedule:

 System administrator can use predefine cron directory as shown below.

 /etc/cron.d
 /etc/cron.daily
 /etc/cron.hourly
 /etc/cron.monthly
 /etc/cron.weekly 

EXAMPLE-3:

List Crontab Entries

# cron -l

output: 00 10 * * * /bin/ls >/ls.txt

EXAMPLE-4:

To remove cron entry:

crontab -i -r

-i is for interactive , it will prompt the user before deleting a job

output: cron: really delete root's cron?

EXAMPLE-5:

To scedule a job for specific time:

The below jobs delete empty files and directory from /tmp at 12:30 am daily.

You need to mention user name to perform crontab command. In below example root user is performing cron job.

# crontab -e
30 0 * * * root find /tmp -type f -empty -delete

EXAMPLE-6:

Special Strings for Common Schedule
Strings Meanings
@reboot Command will run when the system reboot.
@daily Once per day or may use @midnight.
@weekly Once per week.
@yearly Once per year. we can use @annually keyword also.
 

Previous Page
Next Page