Go to main content

Managing System Information, Processes, and Performance in Oracle® Solaris 11.3

Exit Print View

Updated: January 2019
 
 

Overview of Scheduled System Tasks

You can set up many system tasks to execute automatically. Some of these tasks should occur at regular intervals, while others for only a specific duration. Then, there are tasks that need to run only once, perhaps during off peak hours such as evenings and weekends.

This section contains overview information about scheduling system tasks using the Oracle Solaris Service Management Facility (SMF), or the crontab command or at command. Each has a primary function for which it should be used. In general, SMF provides a simpler scheduling mechanism for resource monitoring, though it does have cron-like scheduling capabilities. With SMF, you can set up both periodic services and scheduled services. A periodic service in SMF runs routine tasks within a designated time frame or "interval". An SMF scheduled service always runs according to an assigned start time. To execute repetitive or routine jobs (at a specific start time), use the crontab command. To schedule a single job or to execute a task once (at a specific time), use the at command.

The following table summarizes SMF, the crontab command, and the at command, as well as the files or properties for these functions.

Table 6  Tools for Automatically Executing Tasks
Tool
What It Schedules
Access Control Files or Properties
Periodic SMF service
Multiple system tasks at regular intervals (relative to the time of previous invocation)
solaris.smf.modify
solaris.smf.manage
Scheduled SMF service
Multiple system tasks at a specific time
scheduled/schedule sets the frequency to run. Other scheduled properties specify the time to run.
crontab command
Multiple system tasks at regular intervals (but at specific times)
/var/spool/cron/crontabs
at command
A single system task at a specific time
/var/spool/cron/atjobs

Scheduling a Periodic or Scheduled Task With SMF

You can manage running applications or services with a Solaris service management facility known as SMF. Services are represented in the SMF framework by service objects, instance objects, and their configuration settings. The configuration of the local Oracle Solaris instance is called the localhost scope, and is the only supported scope as of now. For additional information, see the smf(5) man page.

SMF services that help systems run routine maintenance tasks at regular intervals are called periodic or scheduled services. A scheduled service is a type of periodic service that occurs at a specific time. Use a scheduled service for tasks that run occasionally or on a specific schedule (such as off-peak hours). For more information on scheduled services, see Chapter 4, Creating a Service to Run on a Specific Schedule in Developing System Services in Oracle Solaris 11.3.

A periodic service, on the other hand, begins the start method at a time relative to the last run. It is used for maintenance tasks that occur more frequently or regularly. In SMF, a periodic service is managed by the delegated restarter svc:/system/svc/periodic-restarter. This restarter runs the start method only for the instances that it manages. Thus, the scheduled task will begin only at specified intervals for the duration of time that such instances are online. For more information on periodic services, see Chapter 3, Creating a Service to Run Periodically in Developing System Services in Oracle Solaris 11.3.

The advantages of using SMF to schedule tasks are as follows:

  • Automatically restarts any failed services in dependency order (whereas cron typically does not restart itself)

  • Services are well integrated with the operating system and can easily be controlled with dependencies

  • Debugs and reports on service problems, detailing why or how a scheduled service has failed

  • Ensures that the task runs only when the (required) IPS package software is running

  • Requires no additional steps for removing the scheduled task (uninstalls automatically with the IPS package)

  • Delegates tasks to non-root users, with the ability to modify properties and manage services (which is not possible in cron)

  • Manages multiple users in different time zones and settings


Note -  Users without root access are unable to create their own scheduled services in SMF. Therefore, the cron or at commands are the only options for underprivileged users.

For step-by-step instructions on scheduling SMF tasks, see Scheduling Repetitive System Tasks Using SMF.

Scheduling a Routine System Task With crontab Command

cron runs a process that executes commands at specified dates and times. Unlike SMF, it only examines crontab or at command files during its own process initialization phase or when the two commands are run. It does not check for new or changed files at regularly scheduled intervals.

You can specify regularly scheduled commands to cron according to instructions found in the crontab files. Users can submit their own system tasks in cron using the crontab command; root access is not required as it is for SMF. The crontab command also allows you to schedule tasks that need to be executed more than once, whereas the at command only allows for a one-time run. Note that cron never exits, so it should be executed only once.

For step-by-step instructions on scheduling crontab jobs, see How to Create or Edit a crontab File.

Scheduling a Single System Task With at Command

The at command enables you to schedule a one-time task or an infrequent task for execution at a prescribed time. The job can consist of a single command or script.

Similar to crontab, the at command allows you to schedule the automatic execution of a system task. However, unlike crontab files, at files execute their tasks just once. They are then removed from their directory. Therefore, the at command is most useful for running simple commands or scripts that direct output into separate files for later examination.

Submitting an at job involves typing a command and following the at command syntax to specify options in order to schedule the time your job will be executed. For more information about submitting at jobs, see Submitting an at Job File.

The at command stores the command or script you ran, along with a copy of your current environment variable, in the /var/spool/cron/atjobs directory. The file name for an at job consists of a long number that specifies its location in the at queue followed by the .a extension, for example, 793962000.a.

The cron daemon checks for at jobs at startup and listens for new jobs that are submitted. After the cron daemon executes an at job, the at job's file is removed from the atjobs directory. For more information, see the at(1) man page.

For step-by-step instructions on scheduling at jobs, see How to Create an at Job.

Examples of Repetitive System Tasks

You can schedule routine system administration tasks to execute daily, weekly, or monthly. Depending on the task requirements or assigned access control rights, you can use any one of the scheduling tools mentioned in Overview of Scheduled System Tasks.

    Daily system administration tasks might include the following:

  • Removing files more than a few days old from temporary directories

  • Executing accounting summary commands

  • Taking snapshots of the system by using the df and ps commands

  • Performing daily security monitoring

  • Running system backups

    Weekly system administration tasks might include the following:

  • Rebuilding the catman database for use by the man -k command

  • Running the fsck -n command to list any disk problems

    Monthly system administration tasks might include the following:

  • Listing files not used during a specific month

  • Producing monthly accounting reports

Additionally, you can schedule other routine system tasks, such as sending reminders and removing backup files.