Skip Navigation Links | |
Exit Print View | |
System Administration Guide: Advanced Administration Oracle Solaris 11 Express 11/10 |
1. Managing Terminals, Modems and Serial Port Services (Tasks)
2. Displaying and Changing System Information (Tasks)
3. Scheduling System Tasks (Tasks)
Creating and Editing crontab Files (Task Map)
Ways to Automatically Execute System Tasks
For Scheduling Repetitive Jobs: crontab
For Scheduling a Single Job: at
Scheduling a Repetitive System Task (cron)
How the cron Daemon Handles Scheduling
Syntax of crontab File Entries
Controlling Access to the crontab Command
How to Deny crontab Command Access
How to Limit crontab Command Access to Specified Users
How to Verify Limited crontab Command Access
Using the at Command (Task Map)
Scheduling a Single System Task (at)
Controlling Access to the at Command
How to Deny Access to the at Command
How to Verify That at Command Access Is Denied
4. Managing System Processes (Tasks)
5. Monitoring System Performance (Tasks)
6. Troubleshooting Software Problems (Tasks)
7. Managing Core Files (Tasks)
8. Managing System Crash Information (Tasks)
The simplest way to create a crontab file is to use the crontab -e command. This command invokes the text editor that has been set for your system environment. The default editor for your system environment is defined in the EDITOR environment variable. If this variable has not been set, the crontab command uses the default editor, ed. Preferably, you should choose an editor that you know well.
The following example shows how to determine if an editor has been defined, and how to set up vi as the default.
$ which $EDITOR $ $ EDITOR=vi $ export EDITOR
When you create a crontab file, it is automatically placed in the /var/spool/cron/crontabs directory and is given your user name. You can create or edit a crontab file for another user, or root, if you have superuser privileges.
If you are creating or editing a crontab file that belongs to root or another user you must become root.
You do not need to be root to edit your own crontab file.
# crontab -e [username]
where username specifies the name of the user's account for which you want to create or edit a crontab file. You can create your own crontab file without superuser privileges, but you must have superuser privileges to creating or edit a crontab file for root or another user.
Follow the syntax described in Syntax of crontab File Entries. The crontab file will be placed in the /var/spool/cron/crontabs directory.
# crontab -l [username]
Example 3-1 Creating a crontab File
The following example shows how to create a crontab file for another user.
# crontab -e jones
The following command entry added to a new crontab file automatically removes any log files from the user's home directory at 1:00 a.m. every Sunday morning. Because the command entry does not redirect output, redirect characters are added to the command line after *.log. Doing so ensures that the command executes properly.
# This command helps clean up user accounts. 1 0 * * 0 rm /home/jones/*.log > /dev/null 2>&1
$ ls -l /var/spool/cron/crontabs -rw-r--r-- 1 root sys 190 Feb 26 16:23 adm -rw------- 1 root staff 225 Mar 1 9:19 jones -rw-r--r-- 1 root root 1063 Feb 26 16:23 lp -rw-r--r-- 1 root sys 441 Feb 26 16:25 root -rw------- 1 root staff 60 Mar 1 9:15 smith -rw-r--r-- 1 root sys 308 Feb 26 16:23 sys
Verify the contents of user's crontab file by using the crontab -l command as described in How to Display a crontab File.