<chapter id="sysrescron-18108"><title>Scheduling System
Tasks (Tasks)</title><highlights><para>This chapter describes how to schedule routine or single (one-time)
system tasks by using the <command>crontab</command> and <command>at</command> commands. </para><itemizedlist><para>This chapter also explains how to control access to these commands by
using the following files:</para><listitem><para><filename>cron.deny</filename></para>
</listitem><listitem><para><filename>cron-allow</filename></para>
</listitem><listitem><para><filename>at.deny</filename></para>
</listitem>
</itemizedlist><itemizedlist><para>For information on the procedures that are associated with scheduling
system tasks, see the following:</para><listitem><para><olink targetptr="enmwx" remap="internal">Creating and Editing crontab Files
(Task Map)</olink></para>
</listitem><listitem><para><olink targetptr="enmww" remap="internal">Using the at Command (Task Map)</olink></para>
</listitem>
</itemizedlist>
</highlights><sect1 id="enmwx"><title>Creating and Editing <filename>crontab</filename> Files
(Task Map)</title><informaltable frame="all"><tgroup cols="3" colsep="1" rowsep="1"><colspec colwidth="26.50*"/><colspec colwidth="38.51*"/><colspec colwidth="34.00*"/><thead><row><entry><para>Task</para>
</entry><entry><para>Description</para>
</entry><entry><para>For Instructions</para>
</entry>
</row>
</thead><tbody><row><entry><para>Create or edit a <filename>crontab</filename> file.</para>
</entry><entry><para>Use the <command>crontab</command> <option>e</option> command to create
or edit a <filename>crontab</filename> file.</para>
</entry><entry><para><olink targetptr="sysrescron-72169" remap="internal">How to Create or Edit a crontab
File</olink></para>
</entry>
</row><row><entry><para>Verify that a <filename>crontab</filename> file exists.</para>
</entry><entry><para>Use the <command>ls</command> <option>l</option> command to verify the
contents of the <filename>/var/spool/cron/crontabs</filename> file.</para>
</entry><entry><para><olink targetptr="enmxc" remap="internal">How to Verify That a crontab File Exists</olink></para>
</entry>
</row><row><entry><para>Display a <filename>crontab</filename>file.</para>
</entry><entry><para>Use the <command>ls</command> <option>l</option> command to display
the <filename>crontab</filename> file.</para>
</entry><entry><para><olink targetptr="sysrescron-60540" remap="internal">How to Display a crontab File</olink></para>
</entry>
</row><row><entry><para>Remove a <filename>crontab</filename> file</para>
</entry><entry><para>The <filename>crontab</filename> file is set up with restrictive permissions
Use the <command>crontab -r</command> command, rather than the <command>rm</command> command
to remove a <filename>crontab</filename> file.</para>
</entry><entry><para><olink targetptr="sysrescron-31048" remap="internal">How to Remove a crontab File</olink></para>
</entry>
</row><row><entry><para>Deny <filename>crontab</filename> access</para>
</entry><entry><para>To deny users access to <command>crontab</command> commands, add user
names to the <filename>/etc/cron.d/cron.deny</filename> file by editing this
file. </para>
</entry><entry><para><olink targetptr="sysrescron-88294" remap="internal">How to Deny crontab Command Access</olink></para>
</entry>
</row><row><entry><para>Limit <filename>crontab</filename> access to specified users.</para>
</entry><entry><para>To allow users access to the <filename>crontab</filename> command, add
user names to the <filename>/etc/cron.d/cron.allow</filename> file.</para>
</entry><entry><para><olink targetptr="sysrescron-36206" remap="internal">How to Limit crontab Command Access
to Specified Users</olink></para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect1><sect1 id="sysrescron-68"><title>Ways to Automatically Execute System Tasks</title><para>You can set up many system tasks
to execute automatically. Some of these tasks should occur at regular intervals.
Other tasks need to run only once, perhaps during off hours such as evenings
or weekends. </para><para>This section contains overview information
about two commands, <command>crontab</command> and <command>at</command>,
which enable you to schedule routine tasks to execute automatically. The <command>crontab</command>  command schedules repetitive commands. The <command>at</command> command
schedules tasks that execute once.   </para><para>The following table summarizes <command>crontab</command> and <command>at</command> commands, as well as the files that enable you to control access
to these commands.</para><table frame="topbot" id="sysrescron-20472"><title>Command Summary: Scheduling
System Tasks</title><tgroup cols="4" colsep="0" rowsep="1"><colspec colname="column1" colwidth="53.67*"/><colspec colname="column2" colwidth="58.75*"/><colspec colname="column3" colwidth="131.18*"/><colspec colname="column4" colwidth="115.42*"/><thead><row><entry><para>Command</para>
</entry><entry><para>What It Schedules</para>
</entry><entry><para>Location of Files</para>
</entry><entry><para>Files That Control Access</para>
</entry>
</row>
</thead><tbody><row rowsep="0"><entry><para><command>crontab</command> </para>
</entry><entry><para>Multiple system tasks at regular intervals</para>
</entry><entry><para><filename>/var/spool/cron/crontabs</filename></para>
</entry><entry><para><filename>/etc/cron.d/cron.allow</filename> and <filename>/etc/cron.d/cron.deny</filename></para>
</entry>
</row><row><entry><para><command>at</command> </para>
</entry><entry><para>A single system task </para>
</entry><entry><para><filename>/var/spool/cron/atjobs</filename></para>
</entry><entry><para><filename>/etc/cron.d/at.deny</filename></para>
</entry>
</row>
</tbody>
</tgroup>
</table><para>You can also use the Solaris Management Console's Scheduled Jobs tool
to schedule routine tasks. For information on using and starting the Solaris
Management Console, see <olink targetdoc="sysadv1" targetptr="smcover-1" remap="external">Chapter 2, <citetitle remap="chapter">Working With the Solaris Management Console (Tasks),</citetitle> in <citetitle remap="book">System Administration Guide: Basic Administration</citetitle></olink>.</para><sect2 id="sysrescron-95"><title>For Scheduling Repetitive Jobs: <command>crontab</command></title><para>You can schedule routine system administration tasks to execute daily,
weekly, or monthly by using the <command>crontab</command> command. </para><itemizedlist><para>Daily <command>crontab</command> system
administration tasks might include the following:</para><listitem><para>Removing files more than a few days old from temporary directories</para>
</listitem><listitem><para>Executing accounting summary commands</para>
</listitem><listitem><para>Taking snapshots of the system by using the <command>df</command> and <command>ps</command> commands</para>
</listitem><listitem><para>Performing daily security monitoring</para>
</listitem><listitem><para>Running system backups</para>
</listitem>
</itemizedlist><itemizedlist><para>Weekly <command>crontab</command> system
administration tasks might include the following:</para><listitem><para>Rebuilding the <filename>catman</filename> database for use
by the <command>man -k</command> command </para>
</listitem><listitem><para>Running the <command>fsck -n</command> command to list
any disk problems </para>
</listitem>
</itemizedlist><itemizedlist><para>Monthly <command>crontab</command> system
administration tasks might include the following:</para><listitem><para>Listing files not used during a specific month</para>
</listitem><listitem><para>Producing monthly accounting reports</para>
</listitem>
</itemizedlist><para>Additionally, users can schedule <command>crontab</command> commands to execute other routine system tasks, such as
sending reminders and removing backup files.   </para><para>For step-by-step instructions on scheduling <command>crontab</command> jobs,
see <olink targetptr="sysrescron-72169" remap="internal">How to Create or Edit a crontab File</olink>.</para>
</sect2><sect2 id="sysresconcepts-1"><title>For Scheduling a Single Job: <command>at</command></title><para>The <command>at</command> command allows you to schedule a job
for execution at a later time. The job can consist of a single command or
a script.</para><para>Similar to <command>crontab</command>, the <command>at</command> command allows you to schedule
the automatic execution of routine tasks. However, unlike <command>crontab</command> files, <command>at</command> files execute their tasks once. Then, they are removed from their
directory. Therefore, the <command>at</command> command is most useful for
running simple commands or scripts that direct output into separate files
for later examination. </para><para>Submitting an <command>at</command> job involves typing a command and
following the <command>at</command> command syntax to specify options to schedule
the time your job will be executed. For more information about submitting <command>at</command> jobs, see <olink targetptr="sysrescron-12091" remap="internal">Description of
the at Command</olink>. </para><para>The <command>at</command> command
stores the command or script you ran, along with a copy of your current environment
variable, in the <filename>/var/spool/cron/atjobs</filename> directory. Your <command>at</command> job file name is given a long number that specifies its location
in the <command>at</command> queue, followed by the <filename>.a</filename> extension,
such as <filename>793962000.a</filename>.  </para><para>The <command>cron</command> daemon checks for <command>at</command> jobs
at startup and listens for new jobs that are submitted. After the <command>cron</command> daemon
executes an <command>at</command> job, the <command>at</command> job's file
is removed from the <filename>atjobs</filename> directory. For more information,
see the <olink targetdoc="refman" targetptr="at-1" remap="external"><citerefentry><refentrytitle>at</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> man page. </para><para>For step-by-step instructions on scheduling <command>at</command> jobs,
see <olink targetptr="sysrescron-26337" remap="internal">How to Create an at Job</olink>.</para>
</sect2>
</sect1><sect1 id="sysrescron-1"><title>Scheduling a Repetitive System Task (<command>cron</command>)</title><para>The following sections describe how to create, edit, display,
and remove <filename>crontab</filename> files, as well as how to control access
to them.</para><sect2 id="sysrescron-2"><title>Inside a <filename>crontab</filename> File</title><para>The <command>cron</command> daemon schedules system tasks according
to commands found within each <filename>crontab</filename> file. A <filename>crontab</filename> file consists of commands, one command per line, that will be
executed at regular intervals. The beginning of each line contains date and
time information that tells the <command>cron</command> daemon when to execute
the command.</para><para>For example, a <filename>crontab</filename> file
named <filename>root</filename> is supplied during SunOS software installation.
The file's contents include these command lines: </para><screen width="100">10 3 * * * /usr/sbin/logadm <lineannotation>(1)</lineannotation>
15 3 * * 0 /usr/lib/fs/nfs/nfsfind <lineannotation>(2)</lineannotation>
1 2 * * * [ -x /usr/sbin/rtc ] &amp;&amp; /usr/sbin/rtc -c > /dev/null 2>&amp;1 <lineannotation>(3)</lineannotation>
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] &amp;&amp; /usr/lib/gss/gsscred_clean <lineannotation>(4)</lineannotation></screen><itemizedlist><para>The following describes the output for each of these command lines:</para><listitem><para>The first line runs the <command>logadm</command> command
at 3:10 a.m. every day. </para>
</listitem><listitem><para>The second line executes the <command>nfsfind</command> script
every Sunday at 3:15 a.m.</para>
</listitem><listitem><para>The third line runs a script that checks for daylight savings
time (and make corrections, if necessary) at 2:10 a.m. daily.</para><para>If
there is no RTC time zone, nor an <filename>/etc/rtc_config</filename> file,
this entry does nothing. </para><note arch="x86"><para>The <command>/usr/sbin/rtc</command> script can only
be run on an x86 based system.</para>
</note>
</listitem><listitem><para>The fourth line checks for (and removes) duplicate entries
in the Generic Security Service table, <filename>/etc/gss/gsscred_db</filename>,
at 3:30 a.m. daily.</para>
</listitem>
</itemizedlist><para>For more information about the syntax of lines within a <filename>crontab</filename> file,
see <olink targetptr="sysrescron-62861" remap="internal">Syntax of crontab File Entries</olink>.</para><para>The <filename>crontab</filename> files
are stored in the <filename>/var/spool/cron/crontabs</filename> directory.
Several <filename>crontab</filename> files besides <filename>root</filename> are
provided during SunOS software installation. See the following table.</para><table frame="topbot" id="sysrescron-tbl-3"><title>Default <filename>crontab</filename> Files</title><tgroup cols="2" colsep="0" rowsep="0"><colspec colname="column1" colwidth="162*"/><colspec colname="column2" colwidth="195*"/><thead><row rowsep="1"><entry><para><filename>crontab</filename> File</para>
</entry><entry><para>Function</para>
</entry>
</row>
</thead><tbody><row><entry><para><filename>adm</filename> </para>
</entry><entry><para>Accounting</para>
</entry>
</row><row><entry><para><filename>lp</filename> </para>
</entry><entry><para>Printing</para>
</entry>
</row><row><entry><para><filename>root</filename> </para>
</entry><entry><para>General system functions and file system cleanup</para>
</entry>
</row><row><entry><para><filename>sys</filename> </para>
</entry><entry><para>Performance data collection</para>
</entry>
</row><row><entry><para><filename>uucp</filename> </para>
</entry><entry><para>General <literal>uucp</literal> cleanup</para>
</entry>
</row>
</tbody>
</tgroup>
</table><para>Besides the default <filename>crontab</filename> files, users can create <filename>crontab</filename> files to schedule their own system tasks. Other <filename>crontab</filename> files are named after the user accounts in which they are created,
such as <literal>bob</literal>, <literal>mary</literal>, <literal>smith</literal>,
or <literal>jones</literal>.</para><para>To access <filename>crontab</filename> files that belong to <literal>root</literal> or
other users, superuser privileges are required.</para><para>Procedures explaining how to
create, edit, display, and remove <filename>crontab</filename> files are described
in subsequent sections.</para>
</sect2><sect2 id="sysrescron-26552"><title>How the <command>cron</command> Daemon
Handles Scheduling</title><para>The <command>cron</command> daemon
manages the automatic scheduling of <command>crontab</command> commands. The
role of the <command>cron</command> daemon is to check the <filename>/var/spool/cron/crontab</filename> directory for the presence of <filename>crontab</filename> files. </para><itemizedlist><para>The <command>cron</command> daemon performs the following tasks at startup:</para><listitem><para>Checks for new <filename>crontab</filename> files.</para>
</listitem><listitem><para>Reads the execution times that are listed within the files.</para>
</listitem><listitem><para>Submits the commands for execution at the proper times.</para>
</listitem><listitem><para>Listens for notifications from the <command>crontab</command> commands
regarding updated <filename>crontab</filename> files.</para>
</listitem>
</itemizedlist><para>In much
the same way, the <filename>cron</filename> daemon controls the scheduling
of <command>at</command> files. These files are stored in the <filename>/var/spool/cron/atjobs</filename> directory. The <command>cron</command> daemon also listens for
notifications from the <command>crontab</command> commands regarding submitted <command>at</command> jobs.</para>
</sect2><sect2 id="sysrescron-62861"><title>Syntax of <filename>crontab</filename> File
Entries</title><para>A <filename>crontab</filename> file
consists of commands, one command per line, that execute automatically at
the time specified by the first five fields of each command line. These five
fields, described in the following table, are separated by spaces.</para><table frame="topbot" id="sysrescron-68345"><title>Acceptable Values for <filename>crontab</filename> Time Fields</title><tgroup cols="2" colsep="0" rowsep="0"><colspec colname="column1" colwidth="180*"/><colspec colname="column2" colwidth="180*"/><thead><row rowsep="1"><entry><para>Time Field</para>
</entry><entry><para>Values</para>
</entry>
</row>
</thead><tbody><row><entry><para>Minute </para>
</entry><entry><para>0-59</para>
</entry>
</row><row><entry><para>Hour</para>
</entry><entry><para>0-23</para>
</entry>
</row><row><entry><para>Day of month</para>
</entry><entry><para>1-31</para>
</entry>
</row><row><entry><para>Month</para>
</entry><entry><para>1-12</para>
</entry>
</row><row><entry><para>Day of week</para>
</entry><entry><para>0-6 (0 = Sunday)</para>
</entry>
</row>
</tbody>
</tgroup>
</table><itemizedlist><para>Follow these guidelines for using special characters in <filename>crontab</filename> time
fields:</para><listitem><para>Use a space to separate each field.</para>
</listitem><listitem><para>Use a comma to separate multiple values.</para>
</listitem><listitem><para>Use a hyphen to designate a range of values.</para>
</listitem><listitem><para>Use an asterisk as a wildcard to include all possible values. </para>
</listitem><listitem><para>Use a comment mark (#) at the beginning of a line to indicate
a comment or a blank line. </para>
</listitem>
</itemizedlist><para>For example, the following <command>crontab</command> command entry
displays a reminder in the user's console window at 4 p.m. on the first and
fifteenth days of every month.  </para><screen>0 16 1,15 * * echo Timesheets Due > /dev/console</screen><para>Each command within a <filename>crontab</filename> file must consist of one line, even if that line is very
long. The <command>crontab</command> file does not recognize extra carriage
returns. For more detailed information about <filename>crontab</filename> entries
and command options, refer to the <olink targetdoc="refman" targetptr="crontab-1" remap="external"><citerefentry><refentrytitle>crontab</refentrytitle><manvolnum>1</manvolnum></citerefentry></olink> man
page.</para>
</sect2>
</sect1><sect1 id="sysrescron-24589"><title>Creating and Editing <filename>crontab</filename> Files</title><para>The simplest way to create a <filename>crontab</filename> file is to
use the <command>crontab -e</command> 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 <filename>EDITOR</filename> environment
variable. If this variable has not been set, the <command>crontab</command> command
uses the default editor, <command>ed</command>. Preferably, you should choose
an editor that you know well.</para><para>The following
example shows how to determine if an editor has been defined, and how to set
up <command>vi</command> as the default. </para><screen>$ <userinput>which $EDITOR</userinput>
$ 
$ <userinput>EDITOR=vi</userinput>
$ <userinput>export EDITOR</userinput></screen><para>When you create a <filename>crontab</filename> file, it is automatically
placed in the <filename>/var/spool/cron/crontabs</filename> directory and
is given your user name. You can create or edit a <filename>crontab</filename> file
for another user, or <literal>root</literal>, if you have superuser privileges. </para><task id="sysrescron-72169"><title>How to Create or Edit a <filename>crontab</filename> File</title><taskprerequisites><para>If you are creating or editing a <filename>crontab</filename> file that
belongs to <literal>root</literal> or another user you must become superuser
or assume an equivalent role. Roles contain authorizations and privileged
commands. For more information about roles, see <olink targetdoc="sysadv6" targetptr="rbactask-15" remap="external"><citetitle remap="section">Configuring RBAC (Task Map)</citetitle> in <citetitle remap="book">System Administration Guide: Security Services</citetitle></olink></para><para>You do not need to become superuser to edit your own <filename>crontab</filename>file.</para>
</taskprerequisites><procedure><step id="sysrescron-step-7"><para>Create a new <filename>crontab</filename> file,
or edit an existing file. </para><screen>$ <userinput>crontab -e</userinput> [<replaceable>username</replaceable>]</screen><para>where <replaceable>username</replaceable> specifies the name of the
user's account for which you want to create or edit a <filename>crontab</filename> file.
You can create your own <filename>crontab</filename> file without superuser
privileges, but you must have superuser privileges to creating or edit a <filename>crontab</filename> file for <literal>root</literal> or another user.</para><caution><para>If you accidentally type the <command>crontab</command> command
with no option, press the interrupt character for your editor. This character
allows you to quit without saving changes. If you instead saved changes and
exited the file, the existing <filename>crontab</filename> file would be overwritten
with an empty file.   </para>
</caution>
</step><step id="sysrescron-step-8"><para>Add command lines to the <filename>crontab</filename> file.</para><para>Follow the syntax described in <olink targetptr="sysrescron-62861" remap="internal">Syntax
of crontab File Entries</olink>. The <filename>crontab</filename> file will
be placed in the <filename>/var/spool/cron/crontabs</filename> directory.</para>
</step><step id="sysrescron-step-57"><para>Verify your <filename>crontab</filename> file
changes.</para><screen># <userinput>crontab -l</userinput> [<replaceable>username</replaceable>]</screen>
</step>
</procedure><example id="emjfd"><title>Creating a <filename>crontab</filename> File</title><para>The following example shows how to create a <filename>crontab</filename> file
for another user. </para><screen># <userinput>crontab -e jones</userinput></screen><para>The following command entry added to a new <filename>crontab</filename> 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 <filename>*.log</filename>.
Doing so ensures that the command executes properly.</para><screen># This command helps clean up user accounts.
1 0 * * 0 rm /home/jones/*.log > /dev/null 2>&amp;1</screen>
</example>
</task><task id="enmxc"><title>How to Verify That a <filename>crontab</filename> File
Exists</title><procedure remap="single-step"><step><para>To verify that a <filename>crontab</filename> file exists for
a user, use the <command>ls -l</command> command in the <filename>/var/spool/cron/crontabs</filename> directory. For example, the following output shows that <filename>crontab</filename> files exist for users <literal>jones</literal> and <literal>smith</literal>.
  </para><screen>$ <userinput>ls -l /var/spool/cron/crontabs</userinput>
-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</screen><para>Verify the contents of user's <filename>crontab</filename> file by using
the <command>crontab -l</command> command as described in <olink targetptr="sysrescron-60540" remap="internal">How to Display a crontab File</olink>.</para>
</step>
</procedure>
</task>
</sect1><sect1 id="sysrescron-12"><title>Displaying <filename>crontab</filename> Files</title><para>The <command>crontab -l</command> command displays
the contents of a <filename>crontab</filename> file much the same way that
the <command>cat</command> command displays the contents of other types of
files. You do not have to change the directory to <filename>/var/spool/cron/crontabs</filename> directory (where <command>crontab</command> files are located)
to use this command.</para><para>By default, the <command>crontab -l</command> command displays your
own <filename>crontab</filename> file. To display <filename>crontab</filename> files
that belong to other users, you must be superuser.</para><task id="sysrescron-60540"><title>How to Display a <command>crontab</command> File</title><taskprerequisites><para>Become superuser or assume an equivalent role to display a <filename>crontab</filename> file that belongs to <literal>root</literal> or another user.
Roles contain authorizations and privileged commands. For more information
about roles, see <olink targetdoc="sysadv6" targetptr="rbactask-15" remap="external"><citetitle remap="section">Configuring RBAC (Task Map)</citetitle> in <citetitle remap="book">System Administration Guide: Security Services</citetitle></olink>.</para><para>You do not need to become superuser or assume an equivalent role to
display your own <filename>crontab</filename> file.</para>
</taskprerequisites><procedure remap="single-step"><step id="sysrescron-step-15"><para>Display the <filename>crontab</filename> file.
 </para><screen>$ <userinput>crontab -l</userinput> [<replaceable>username</replaceable>]</screen><para>where <replaceable>username</replaceable> specifies the name of the
user's account for which you want to display a <filename>crontab</filename> file.
Displaying another user's <filename>crontab</filename> file requires superuser
privileges.</para><caution><para>If you accidentally type the <command>crontab</command> command
with no option, press the interrupt character for your editor. This character
allows you to quit without saving changes. If you instead saved changes and
exited the file, the existing <filename>crontab</filename> file would be overwritten
with an empty file.</para>
</caution>
</step>
</procedure><example id="emjgd"><title>Displaying a <filename>crontab</filename> File</title><para>This example shows how to use the <command>crontab
-l</command> command to display the contents of the user's default <filename>crontab</filename> file.</para><screen>$ <userinput>crontab -l</userinput>
13 13 * * * chmod g+w /home1/documents/*.book > /dev/null 2>&amp;1</screen>
</example><example id="enmxd"><title>Displaying the Default <literal>root</literal> <filename>crontab</filename> file.</title><para>This example shows how to display the default <literal>root</literal> <filename>crontab</filename> file.</para><screen>$ <userinput>su</userinput>Password:
Sun Microsystems Inc.   SunOS 5.10      s10_51  May 2004
# <userinput>crontab -l</userinput>
#ident  "@(#)root       1.19    98/07/06 SMI"   /* SVr4.0 1.1.3.1       */
#
# The root crontab should be used to perform accounting data collection.
#
#
10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] &amp;&amp; /usr/lib/gss/gsscred_clean
#10 3 * * * /usr/lib/krb5/kprop_script ___slave_kdcs___</screen>
</example><example id="enmxf"><title>Displaying the <filename>crontab</filename> File of Another User</title><para>This example shows how to display the <filename>crontab</filename> file
that belongs to another user.</para><screen>$ <userinput>su</userinput>
Password:
Sun Microsystems Inc.   SunOS 5.10      s10_51  May 2004
# <userinput>crontab -l jones</userinput>
13 13 * * * cp /home/jones/work_files /usr/backup/. > /dev/null 2>&amp;1</screen>
</example>
</task>
</sect1><sect1 id="sysrescron-17"><title>Removing <filename>crontab</filename> Files</title><para>By default, <filename>crontab</filename> file
protections are set up so that you cannot inadvertently delete a <filename>crontab</filename> file by using the <command>rm</command> command. Instead, use
the <command>crontab -r</command> command to remove <filename>crontab</filename> files.
  </para><para>By default, the <command>crontab -r</command> command removes your own <filename>crontab</filename> file. </para><para>You do not have to change the directory to <filename>/var/spool/cron/crontabs</filename> (where <filename>crontab</filename> files are located) to use
this command.</para><task id="sysrescron-31048"><title>How to Remove a <filename>crontab</filename> File</title><taskprerequisites><para>Become superuser or assume an equivalent role to remove a <filename>crontab</filename> file that belongs to <literal>root</literal> or another user.
Roles contain authorizations and privileged commands. For more information
about roles, see <olink targetdoc="sysadv6" targetptr="rbactask-15" remap="external"><citetitle remap="section">Configuring RBAC (Task Map)</citetitle> in <citetitle remap="book">System Administration Guide: Security Services</citetitle></olink>.</para><para>You do not need to become superuser or assume an equivalent role to
remove your own <filename>crontab</filename> file.</para>
</taskprerequisites><procedure><step id="sysrescron-step-20"><para>Remove the <filename>crontab</filename> file.
 </para><screen>$ <userinput>crontab -r</userinput> [<replaceable>username</replaceable>]</screen><para>where <replaceable>username</replaceable> specifies the name of the
user's account for which you want to remove a <filename>crontab</filename> file.
Removing <filename>crontab</filename> files for another user requires superuser
privileges.</para><caution><para>If you accidentally type the <command>crontab</command> command
with no option, press the interrupt character for your editor. This character
allows you to quit without saving changes. If you instead saved changes and
exited the file, the existing <filename>crontab</filename> file would be overwritten
with an empty file.</para>
</caution>
</step><step id="sysrescron-step-58"><para>Verify that the <filename>crontab</filename> file
has been removed.</para><screen># <userinput>ls /var/spool/cron/crontabs</userinput></screen>
</step>
</procedure><example id="emjfi"><title>Removing a <filename>crontab</filename> File</title><para>The following example shows how user <literal>smith</literal> uses
the <command>crontab -r</command> command to remove his <filename>crontab</filename> file.
  </para><screen>$ <userinput>ls /var/spool/cron/crontabs</userinput>
adm     jones     lp     root    smith    sys     uucp
$ <userinput>crontab -r</userinput>
$ <userinput>ls /var/spool/cron/crontabs</userinput>
adm     jones     lp     root    sys    uucp</screen>
</example>
</task>
</sect1><sect1 id="sysrescron-23"><title>Controlling Access to the <command>crontab</command> Command</title><para>You can control access to the <command>crontab</command> command
by using two files in the <filename>/etc/cron.d</filename> directory: <filename>cron.deny</filename> and <filename>cron.allow</filename>. These files permit only specified
users to perform <command>crontab</command> command tasks such as creating,
editing, displaying, or removing their own <filename>crontab</filename> files.
      </para><para>The <filename>cron.deny</filename> and <filename>cron.allow</filename> files
consist of a list of user names, one user name per line. </para><itemizedlist><para>These access control files work together as follows:</para><listitem><para>If <filename>cron.allow</filename> exists,
only the users who are listed in this file can create, edit, display, or remove <command>crontab</command> files. </para>
</listitem><listitem><para>If <filename>cron.allow</filename> does not exist, all users
can submit <command>crontab</command> files, except for users who are listed
in <filename>cron.deny</filename>. </para>
</listitem><listitem><para>If neither <filename>cron.allow</filename> nor <filename>cron.deny</filename> exists, superuser privileges are required to run the <command>crontab</command> command.</para>
</listitem>
</itemizedlist><para>Superuser privileges are required to edit or create the <filename>cron.deny</filename> and <filename>cron.allow</filename> files.</para><para>The <filename>cron.deny</filename> file,
which is created during SunOS software installation, contains the following
user names: </para><screen>$ <userinput>cat /etc/cron.d/cron.deny</userinput>
daemon
bin
smtp
nuucp
listen
nobody
noaccess</screen><para>None of the user names in the default <filename>cron.deny</filename> file
can access the <command>crontab</command> command. You can edit this file
to add other user names that will be denied access to the <command>crontab</command> command.</para><para>No
default <filename>cron.allow</filename> file is supplied. So, after Solaris
software installation, all users (except users who are listed in the default <filename>cron.deny</filename> file) can access the <command>crontab</command> command.
If you create a <filename>cron.allow</filename> file, only these users can
access the <command>crontab</command> command.          </para><task id="sysrescron-88294"><title>How to Deny <command>crontab</command> Command
Access</title><procedure>&rolestep.sgm;<step id="sysrescron-step-26"><para>Edit the <filename>/etc/cron.d/cron.deny</filename> file and add user names, one user per line.
Include users who will be denied access to the <command>crontab</command> commands.</para><screen>daemon
bin
smtp
nuucp
listen
nobody
noaccess
<replaceable>username1</replaceable>
<replaceable>username2</replaceable>
<replaceable>username3</replaceable>
.
.
.</screen>
</step><step id="sysrescron-step-64"><para>Verify that the <filename>/etc/cron.d/cron.deny</filename> file contains the new entries.</para><screen># <userinput>cat /etc/cron.d/cron.deny</userinput>
daemon
bin
nuucp
listen
nobody
noaccess</screen>
</step>
</procedure>
</task><task id="sysrescron-36206"><title>How to Limit <command>crontab</command> Command
Access to Specified Users</title><procedure>&rolestep.sgm;<step id="sysrescron-step-30"><para>Create the <filename>/etc/cron.d/cron.allow</filename> file.</para>
</step><step id="sysrescron-step-31"><para>Add the <literal>root</literal> user name
into the <filename>cron.allow</filename> file.</para><para>If you do not add <literal>root</literal> to the file, superuser access to <command>crontab</command> commands
will be denied. </para>
</step><step id="sysrescron-step-66"><para>Add the user names, one user name per
line. Include users that will be allowed to use the <command>crontab</command> command.</para><screen><userinput>root</userinput>
<replaceable>username1</replaceable>
<replaceable>username2</replaceable>
<replaceable>username3</replaceable>
<replaceable>.</replaceable>
<replaceable>.</replaceable>
<replaceable>.</replaceable></screen>
</step>
</procedure><example id="emjgb"><title>Limiting <command>crontab</command> Command Access to Specified Users</title><para>The following example shows a <filename>cron.deny</filename> file that
prevents user names <filename>jones</filename>, <filename>temp</filename>,
and <filename>visitor</filename> from accessing the <command>crontab</command> command.</para><screen>$ <userinput>cat /etc/cron.d/cron.deny</userinput>
daemon
bin
smtp
nuucp
listen
nobody
noaccess
jones
temp
visitor</screen><para>The following example
shows a <filename>cron.allow</filename> file. The users <literal>root</literal>, <literal>jones</literal>, <literal>lp</literal>, and <literal>smith</literal> are the
only users who can access the <command>crontab</command> command.       </para><screen>$ <userinput>cat /etc/cron.d/cron.allow</userinput>
root
jones
lp
smith</screen>
</example>
</task><sect2 id="sysrescron-60"><title>How to Verify Limited <command>crontab</command> Command
Access</title><para>To verify if a specific user can access the <command>crontab</command> command,
use the  <command>crontab -l</command> command while you are logged into the
user account.  </para><screen>$ <userinput>crontab -l</userinput></screen><para>If the user can access the <command>crontab</command> command, and already has created a <filename>crontab</filename> file,
the file is displayed. Otherwise, if the user can access the <command>crontab</command> command
but no <filename>crontab</filename> file exists, a message similar to the
following message is displayed:</para><screen>crontab: can't open your crontab file</screen><para>Either this user either is listed in the <filename>cron.allow</filename> file
(if the file exists), or the user is not listed in the <filename>cron.deny</filename> file. </para><para>If the user cannot access the <command>crontab</command> command, the
following message is displayed whether or not a previous <command>crontab</command> file
exists:  </para><screen>crontab: you are not authorized to use cron. Sorry.</screen><para>This message means that either the user is not listed in the <filename>cron.allow</filename> file (if the file exists), or the user is listed in the <filename>cron.deny</filename> file.</para>
</sect2>
</sect1><sect1 id="enmww"><title>Using the <command>at</command> Command (Task Map)</title><informaltable frame="all"><tgroup cols="3" colsep="1" rowsep="1"><colspec colwidth="33*"/><colspec colwidth="33*"/><colspec colwidth="33*"/><thead><row><entry><para>Task</para>
</entry><entry><para>Description</para>
</entry><entry><para>For Instructions</para>
</entry>
</row>
</thead><tbody><row><entry><para>Create an <command>at</command> job.</para>
</entry><entry><itemizedlist><para>Use the <command>at</command>command to do the following:</para><listitem><para>Start the <command>at</command> utility from the command line.</para>
</listitem><listitem><para>Type the commands or scripts that you want to execute, one
per line.</para>
</listitem><listitem><para>Exit the <command>at</command> utility and save the job.</para>
</listitem>
</itemizedlist>
</entry><entry><para><olink targetptr="sysrescron-26337" remap="internal">How to Create an at Job</olink></para>
</entry>
</row><row><entry><para>Display the <command>at</command> queue.</para>
</entry><entry><para>User the <command>atq</command> command to display the <command>at</command> queue.</para>
</entry><entry><para><olink targetptr="enmxg" remap="internal">How to Display the at Queue</olink></para>
</entry>
</row><row><entry><para>Verify an <command>at</command> job.</para>
</entry><entry><para>Use the <command>atq</command> command to confirm that <filename>at</filename> jobs
that belong to a specific user have been submitted to the queue.</para>
</entry><entry><para><olink targetptr="enmxi" remap="internal">How to Verify an at Job</olink></para>
</entry>
</row><row><entry><para>Display <command>at</command> jobs.</para>
</entry><entry><para>Use the <command>at -l</command>[<replaceable>job-id</replaceable> to
display <command>at</command> jobs. that have been submitted to the queue.</para>
</entry><entry><para><olink targetptr="enmxh" remap="internal">How to Display at Jobs</olink></para>
</entry>
</row><row><entry><para>Remove <command>at</command> jobs.</para>
</entry><entry><para>Use the <command>at -r</command> [<replaceable>job-id</replaceable>]
command to remove <command>at</command> jobs from the queue.</para>
</entry><entry><para><olink targetptr="sysrescron-62698" remap="internal">How to Remove at Jobs</olink></para>
</entry>
</row><row><entry><para>Deny access to the <command>at</command> command.</para>
</entry><entry><para>To deny users access to the <command>at</command>command, edit the <filename>/etc/cron.d/at.deny</filename> file.</para>
</entry><entry><para><olink targetptr="sysrescron-94711" remap="internal">How to Deny Access to the at Command</olink></para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect1><sect1 id="sysrescron-35"><title>Scheduling a Single System Task (<command>at</command>)</title><itemizedlist><para>The following sections describe how to use the <command>at</command> command
to perform the following tasks:</para><listitem><para>Schedule jobs (command and scripts) for execution
at a later time</para>
</listitem><listitem><para>How to display and remove these jobs</para>
</listitem><listitem><para>How to control access to the <command>at</command> command</para>
</listitem>
</itemizedlist><para>By default, users can create, display, and remove their own <command>at</command> job
files. To access <filename>at</filename> files that belong to <literal>root</literal> or
other users, you must have superuser privileges.</para><para>When you submit an <command>at</command> job, it is assigned a job identification
number along with the <filename>.a</filename> extension. This designation
becomes the job's file name, as well as its queue number.</para><sect2 id="sysrescron-12091"><title>Description of the <command>at</command> Command</title><para>Submitting an <command>at</command> job file involves these steps:</para><orderedlist><listitem><para>Invoking the <command>at</command> utility and specifying
a command execution time.</para>
</listitem><listitem><para>Typing a command or script to execute later.</para><note><para>If output from this command or script is important, be sure to
direct the output to a file for later examination.</para>
</note>
</listitem>
</orderedlist><para>For example, the following <command>at</command> job
removes <filename>core</filename> files from the user account <literal>smith</literal> near
midnight on the last day of July.  </para><screen>$ <userinput>at 11:45pm July 31</userinput>
at> <userinput>rm /home/smith/*core*</userinput>
at> <replaceable>Press Control-d</replaceable>
commands will be executed using /bin/csh
job 933486300.a at Tue Jul 31 23:45:00 2004</screen>
</sect2><sect2 id="sysrescron-32173"><title>Controlling Access to the <command>at</command> Command</title><para>You can set
up a file to control access to the <command>at</command> command, permitting
only specified users to create, remove, or display queue information about
their <command>at</command> jobs. The file that controls access to the <command>at</command> command, <filename>/etc/cron.d/at.deny</filename>, consists of
a list of user names, one user name per line. The users who are listed in
this file cannot access <command>at</command> commands.     </para><para>The <filename>at.deny</filename> file, which is created during SunOS
software installation, contains the following user names:  </para><screen>daemon
bin
smtp
nuucp
listen
nobody
noaccess</screen><para>With
superuser privileges, you can edit the <filename>at.deny</filename> file to
add other user names whose <command>at</command> command access you want to
restrict.</para>
</sect2><task id="sysrescron-26337"><title>How to Create an <command>at</command> Job</title><procedure><step id="sysrescron-step-37"><para>Start the <command>at</command> utility, specifying the time you
want your job executed.  </para><screen>$ <userinput>at</userinput> [<userinput>-m</userinput>] <replaceable>time</replaceable> [<replaceable>date</replaceable>] </screen><variablelist><varlistentry><term><command>-m</command></term><listitem><para>Sends you email after the job is completed.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>time</replaceable></term><listitem><para>Specifies the hour that you want to schedule the job. Add <literal>am</literal> or <literal>pm</literal> if you do not specify the hours according
to the 24-hour clock. Acceptable keywords are <literal>midnight</literal>, <literal>noon</literal>, and <literal>now</literal>. Minutes are optional.</para>
</listitem>
</varlistentry><varlistentry><term><replaceable>date</replaceable></term><listitem><para>Specifies the first three or more letters of a month, a day
of the week, or the keywords <literal>today</literal> or <literal>tomorrow</literal>.</para>
</listitem>
</varlistentry>
</variablelist>
</step><step id="sysrescron-step-38"><para>At the <command>at</command> prompt, type
the commands or scripts that you want to execute, one per line. </para><para>You
may type more than one command by pressing Return at the end of each line. </para>
</step><step id="sysrescron-step-39"><para>Exit the <command>at</command> utility
and save the <command>at</command> job by pressing Control-D. </para><para>Your <command>at</command> job is assigned a queue number, which is also the job's file
name. This number is displayed when you exit the <command>at</command> utility. </para>
</step>
</procedure><example id="emjft"><title>Creating an <command>at</command> Job</title><para>The following example shows the <command>at</command> job that
user <literal>jones</literal> created to remove her backup files at 7:30 p.m.
She used the <option>m</option> option so that she would receive an email
message after her job completed.  </para><screen>$ <userinput>at -m 1930</userinput>
at> <userinput>rm /home/jones/*.backup</userinput>
at> <replaceable>Press Control-D</replaceable>
job 897355800.a at Thu Jul  12 19:30:00 2004</screen><para>She received a email message which confirmed the execution of her <command>at</command> job. </para><screen>Your &ldquo;at&rdquo; job &ldquo;<userinput>rm /home/jones/*.backup</userinput>&rdquo;
completed.</screen><para>The
following example shows how <literal>jones</literal> scheduled a large <command>at</command> job for 4:00 a.m. Saturday morning. The job output was directed
to a file named <filename>big.file</filename>.  </para><screen>$ <userinput>at 4 am Saturday</userinput>
at> <userinput>sort -r /usr/dict/words > /export/home/jones/big.file</userinput></screen>
</example>
</task><task id="enmxg"><title>How to Display the <filename>at</filename> Queue</title><procedure remap="single-step"><step><para>To check your jobs that are waiting in the <filename>at</filename> queue,
use the <command>atq</command> command. This command displays status information
about the <command>at</command> jobs that you have created. </para><screen>$ <userinput>atq</userinput></screen>
</step>
</procedure>
</task><task id="enmxi"><title>How to Verify an <filename>at</filename> Job</title><procedure remap="single-step"><step><para>To verify that you have created an <command>at</command> job,
use the <command>atq</command> command. In the following example, the <command>atq</command> command confirms that <filename>at</filename> jobs that belong
to <filename>jones</filename> have been submitted to the queue. </para><screen>$ <userinput>atq</userinput>
Rank	  Execution Date     Owner     Job         Queue   Job Name
  1st   Jul 12, 2004 19:30   jones  897355800.a     a     stdin
  2nd   Jul 14, 2004 23:45   jones  897543900.a     a     stdin
  3rd   Jul 17, 2004 04:00   jones  897732000.a     a     stdin</screen>
</step>
</procedure>
</task><task id="enmxh"><title>How to Display <command>at</command> Jobs</title><procedure remap="single-step"><step><para>To display information about the execution times of your <command>at</command> jobs,
use the <command>at -l</command> command.</para><screen>$ <userinput>at -l</userinput> [<replaceable>job-id</replaceable>]</screen><para>where the <option>l</option> <replaceable>job-id</replaceable> option
identifies the identification number of the job whose status you want to display.</para>
</step>
</procedure><example id="sysrescron-43"><title>Displaying <command>at</command> Jobs</title><para>The following example shows output from the <command>at -l</command> command,
which provides information on the status of all jobs submitted by a user.</para><screen>$ <userinput>at -l</userinput>
897543900.a	Sat Jul 14 23:45:00 2004
897355800.a	Thu Jul 12 19:30:00 2004
897732000.a	Tue Jul 17 04:00:00 2004</screen><para>The
following example shows the output that is displayed when a single job is
specified with the <command>at -l</command> command.</para><screen>$ <userinput>at -l 897732000.a</userinput>
897732000.a		Tue Jul 17 04:00:00 2004</screen>
</example>
</task><task id="sysrescron-62698"><title>How to Remove <command>at</command> Jobs</title><taskprerequisites><para>Become superuser or assume an equivalent role to remove an <filename>at</filename> job
that belongs to <literal>root</literal> or another user. Roles contain authorizations
and privileged commands. For more information about roles, see <olink targetdoc="sysadv6" targetptr="rbactask-15" remap="external"><citetitle remap="section">Configuring RBAC (Task Map)</citetitle> in <citetitle remap="book">System Administration Guide: Security Services</citetitle></olink>.</para><para>You do not need to become superuser or assume an equivalent role to
remove your own <filename>at</filename> job.</para>
</taskprerequisites><procedure><step id="sysrescron-step-46"><para>Remove the <command>at</command> job from
the queue before the job is executed. </para><screen>$ <userinput>at -r</userinput> [<replaceable>job-id</replaceable>]</screen><para>where the <option>r</option> <replaceable>job-id</replaceable> option
specifies the identification number of the job you want to remove.</para>
</step><step id="sysrescron-step-59"><para>Verify that the <command>at</command> job
is removed by using the <command>at -l</command> (or the <command>atq</command>)
command.</para><para>The <command>at -l</command> command displays the jobs
remaining in the <command>at</command> queue. The job whose identification
number you specified should not appear.</para><screen>$ <userinput>at -l</userinput> [<replaceable>job-id</replaceable>]</screen>
</step>
</procedure><example id="emjfk"><title>Removing <command>at</command> Jobs</title><para>In the following example, a user wants to remove an <command>at</command> job that was scheduled to execute at 4 a.m. on July 17th. First,
the user displays the <command>at</command> queue to locate the job identification
number. Next, the user removes this job from the <command>at</command> queue.
Finally, the user verifies that this job has been removed from the queue.
  </para><screen>$ <userinput>at -l</userinput>
897543900.a	Sat Jul 14 23:45:00 2003
897355800.a	Thu Jul 12 19:30:00 2003
897732000.a	Tue Jul 17 04:00:00 2003
$ <userinput>at -r 897732000.a</userinput>
$ <userinput>at -l 897732000.a</userinput>
at: 858142000.a: No such file or directory</screen>
</example>
</task><task id="sysrescron-94711"><title>How to Deny Access to the <command>at</command> Command</title><procedure>&rolestep.sgm;<step id="sysrescron-step-53"><para>Edit the <filename>/etc/cron.d/at.deny</filename> file
and add the names of users, one user name per line, that will be prevented
from using the <command>at</command> commands.  </para><screen>daemon
bin
smtp
nuucp
listen
nobody
noaccess
<replaceable>username1</replaceable>
<replaceable>username2</replaceable>
<replaceable>username3</replaceable>
.
.
.</screen>
</step>
</procedure><example id="emjfu"><title>Denying <command>at</command> Access</title><para>The following example shows an <filename>at.deny</filename> file that has been edited so that the users <literal>smith</literal> and <literal>jones</literal> cannot access the <command>at</command> command.       </para><screen>$ <userinput>cat at.deny</userinput>
daemon
bin
smtp
nuucp
listen
nobody
noaccess
jones
smith</screen>
</example>
</task><task id="enmxk"><title>How to Verify That <command>at</command> Command Access
Is Denied</title><procedure remap="single-step"><step><para>To verify that a username was added correctly to  the <filename>/etc/cron.d/at.deny</filename> file, use the <command>at -l</command> command while logged in
as the user. If the user <literal>smith</literal> cannot access the <command>at</command> command,
the following message is displayed. </para><screen># <userinput>su smith</userinput>
Password:
$ <userinput>at -l</userinput>
at: you are not authorized to use at.  Sorry.</screen><para>Likewise, if the user tries to submit an <command>at</command> job,
the following message is displayed:  </para><screen>$ <userinput>at 2:30pm</userinput>
at: you are not authorized to use at.  Sorry.</screen><para>This message confirms that the user is listed in the <filename>at.deny</filename> file. </para><para>If <command>at</command> command access is allowed, then the <command>at -l</command> command returns nothing.</para>
</step>
</procedure>
</task>
</sect1>
</chapter>