Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

at - execute commands at a later time

&pagelevel(4)&pagelevel

The at command

  • reads commands from standard input or from a shell script and executes them at a later time specified by the user. A command list created in this way runs under a job number. (Format 1 and 2)

  • lists on standard output any jobs scheduled with at or batch (see batch) which have not yet been processed (Format 3 and 4)

  • removes jobs previously scheduled with at or batch (Format 5).

The output from Format 1 and Format 2 is sent to the user by mailx unless the standard output and standard error output of the commands to be executed have been redirected.

The environment variables, the current directory, the permissions for new files (see umask "umask get or set the file mode creation mask") and the maximum permissible file size (see ulimit "ulimit set or report file size limit") are retained, but open files and priorities are lost, and the trap command (shell built-in for catching signals) is deactivated. at writes the job number and the schedule time to standard error.

Jobs scheduled with at are retained even if the user who scheduled them closes the POSIX shell with exit or if the POSIX subsystem is shut down. There is no need to reschedule the jobs.

Before the call

The user ID must have a standard account number for rlogin access. This standard account number can be assigned using the ADD-USER, MODIFY-USER-ATTRIBUTES or ADD-POSIX-USER command.

If the file /usr/lib/cron.d/at.allow exists, you can only use at if your login name appears in it.

If the file /usr/lib/cron.d/at.allow does not exist, you can only use at if your login name does not appear in the file /usr/lib/cron.d/at.deny.

If neither /usr/lib/cron.d/at.allow nor /usr/lib/cron.d/at.deny exists, only the POSIX administrator is allowed to use at.

If only an empty deny file exists, for example, everyone is allowed to use at.

Only the POSIX administrator is allowed to create and modify the allow and deny files. Each line in these files contains precisely one login name.

The cron daemon is started by means of an rc script.

Syntax


Format 1:at[ -m][ -f script][ -q queue] -t time
Format 2:at[ -m][ -f script][ -q queue] time
Format 3:at -l[ jobnumber]
Format 4:at -l -q queue
Format 5:at -r jobnumber
Execute commands at a later time
Format 1:at[ -m][ -f script][ -q queue] -t time


-f script

at reads the commands to be executed from the specified shell script.
You can specify a number of commands, separated from one another by a semicolon (;) or a newline character. A command list created in this way runs under a job number. You can exit the command list terminal-dependent with CTRL+D or @@d.

-f not specified:
at reads the commands to be executed from the standard input.

-m

Sends mail to the user after a job has been completed, indicating that the job is finished. Mail is sent only if the job has not already generated a mail message.

-q queue

The -q option is used to assign a job to a specific queue in the /var/spool/cron directory.

The values accepted for queue are:

a  for the default queue for jobs scheduled with at.

b  for the default queue for jobs scheduled with batch.

c  for the default queue for jobs scheduled with crontab.

-t time

Specifies the execution time for the commands. time is specified as follows: 

[[CC]YY]MMDDhhmm[.SS]

CC

The first two digits of a date (century).
CC not specified:
If the two-digit date is greater than 68, the current century is assumed, otherwise the following is used.

YY

Two-digit year specification.
YY not specified:
The current year is assumed.

MM

Two-digit month specification (01 bis 12)

DD

Two-digit day specification (01 bis 31)

hh

Two-digit hour specification (00 bis 23)

mm

Two-digit minute specification (00 bis 59)

SS

Two-digit second specification (00 bis 61)
The values 60 and 61 are intended for leap seconds.
SS not specified:
The value 0 seconds is assumed.


Format 2:at[ -m][ -f script][ -q queue] time

The options are described under Format 1.

time

Specifies the execution time for the commands. time is specified as follows: 
time[ date][ +increment]

time:

digits[suffix] or special_name

digits

[h]h

hhmm

[h]h:[m]m

1- and 2-digit numbers are interpreted as hours.

4-digit numbers are interpreted as hours and minutes.

Digits separated by a colon are interpreted as hours and minutes.

suffix

am

Interpreted as before 12 noon (dependent from the locale LC_TIME)

pm

Interpreted as after 12 noon (dependent from the locale LC_TIME)

ampm omitted:

Interpreted as 24-hour clock

utc[am|pm] or zulu[am|pm]

Interpreted as UTC (Coordinated Universal Time)

special_name

noonmidnightnow

date:

month day[,year] or
weekday[ nextweek|next week] or 
special_day

month (dependent from the locale LC_TIME)

jan[uary], feb[uary], mar[ch], apr[il], may, jun[e], jul[y], aug[ust], sep[tember], oct[ober], nov[ember], dec[ember], nextmonth | next month

day

A number between 1 and 31, depending on how long the month is.

year

Number defining the year to which the date applies
nextyear | next year: selects the following year
year not specified:
If the date given is before the current date, at assumes the next year; otherwise, the current year.

weekday (dependent from the locale LC_TIME):

mon[day], tue[sday], wed[nesday], thu[rsday], fri[day], sat[urday], sun[day]

nextweek | next week

selects the following week

special_day

today, tomorrow, nextday, next day

nextday (or next day) means that the job is executed a full day later.
If the specified time lies before the current time, at interprets the following day as the current day. For example, if the job at 10 nextday were scheduled at 11:00am on 7/1/95, the job would be executed at 10:00am on 7/3/95; however, if at 14 nextday were specified at the same time, execution would begin at 14:00 hours on 7/2/95.

date not specified:

corresponds to today if the specified time (rounded to the nearest minute) lies after the current time

corresponds to tomorrow if the specified time (rounded to the nearest minute) lies after the current time

corresponds to now if the specified time (rounded to the nearest minute) lies after the current time

+increment

increment is a positive integer that must be followed by one of the following units of time:
minute[s], hour[s], day[s], week[s], month[s], year[s]


Example:

at can typically be specified in the following ways:

at 0815am jan 24 
at 8:15am jan 24 
at 5pm friday 
at now +1hour 
List jobs yet processed
Format 3:at -l[ jobnumber]
Format 4:at -l -q queue

-l[ jobnumber]

at lists the specified jobnumber, if the corresponding job has not yet been processed. jobnumber is the number that is reported on standard error when a job is scheduled with at, batch or cron.

jobnumber not specified:
at lists all jobs that are yet to be processed, together with their job numbers.

-l -q queue

It is possible to specify the queue as an alternative to the jobnumber. at lists all of the jobs in queue.

Remove jobs
Format 5:at -r jobnumber

-r jobnumber

at removes the job jobnumber, which was previously scheduled with at or batchjobnumber is the number reported on standard error when a command job is scheduled with at or batch. You can specify more than one job number, using blanks to separate them. Only the POSIX administrator is authorized to remove another user's jobs.


Error

The commonest error messages are:


at: bad date specification

You have entered the date in an incorrect format.


at: too late

The date you specified has already passed.


at: This job may not be executed at the proper time

time lies between "now" and "now+1hour".


at: you are not authorized to use at. Sorry.

You are not authorized to use at. Sorry. (See Before the call)


File

/usr/lib/cron/at.allow

List of login names with permission to use at. One login name is entered per line.

/usr/lib/cron/at.deny

List of login names explicitly denied permission to use at. One login name is entered per line

/var/spool/cron/atjobs

Directory containing a separate file for each at job which has not yet been executed. Each at job is allocated a file of its own with the file name jobnumber.a.


Variable

SHELL

Determine a name of a command interpreter to be used to invoke the at job. If the variable is unset or null, sh will be used. If it is set to a value other than a name for sh, the implementation will do one of the following: use that shell; use sh; use the login shell from the user database.

TZ

Determine the timezone. The job will be submitted for execution at the time specified be timespec or -t time relative to the timezone specified by the TZ variable. If timespec specifies a timezone, it will override TZ. If timespec does not specify a timezone and TZ is unset or null, an unspecified default timezone will be used.

Locale

The following environment variables affect the execution of at:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files).

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.

LC_TIME

Determine the format of date and time string.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.


Example

The current date and the string April Fool! are to be displayed on terminal tty013 at 9 o’clock in the morning on the 1st of April.
$ at 1pm apr 1

echo `date`":April Fool!" >> /dev/tty013

CTRL+D or @@d


See also

batch, crontab, date, kill, mailx, nice, ps, sh, sort