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". You must be assigned the solaris.smf.modify and the solaris.smf.manage authorizations to configure a periodic service.
A scheduled service in SMF always runs according to an assigned start time. The scheduled/schedule property sets the frequency to run. Other scheduled properties specify the time to run.
To execute repetitive or routine jobs (at a specific start time), use the crontab command. Its interface is /var/spool/cron/crontabs.
To schedule a single job or to execute a task once (at a specific time), use the at command. Its interface is /var/spool/cron/atjobs.
You can manage running applications or services with the Oracle Solaris Service Management Framework (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(7) 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 about scheduled services, see Chapter 4, Creating a Service to Run on a Specific Schedule in Developing System Services in Oracle Solaris 11.4.
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 about periodic services, see Chapter 3, Creating a Service to Run Periodically in Developing System Services in Oracle Solaris 11.4.
The many advantages of using SMF to schedule tasks include:
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
For step-by-step instructions, see Scheduling Repetitive System Tasks With SMF.
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 must be executed more than one time, whereas the at command only allows for a one-time run. Note that cron never exits, so it should be executed only one time.
For step-by-step instructions on scheduling crontab jobs, see How to Create or Edit a crontab File.
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 one time. 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 at which your job executes. For more information about submitting at jobs, see Submitting an at Job.
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.
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
Running 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.