System administrations

at daemon allows you to run the command of your choice, once, at a specified time in the future.

You can set an at job to be run once. The at daemon works to the print process; jobs are spooled in the /var/ spool/at directory and run at the specified time.

You can use the at daemon to run the command or script of your choice. For the purpose of this article we are creating a simple script that will list the contain of current directory and send this output to terminal 2.

From the command line, you can run the at time command to start a job to be run at a specified time. That time can be now; in a specified number of minutes, hours, or days; or at the time of your choice. We will take several example to illustrate it more deeply. The CTRL-D command exits the at command shell and returns to your original command line interface.

Login from root and create a simple script file test.sh and grant it execute permission

create simple scripts

Check date before scheduling job from at commands

date command

To run this script on 21 Feb 2010 after seven days you need to schedule at command as shown here

at command with days

To run this script after ten minutes you need to schedule at command as shown here

at commands with minutes

To run this script now you need to schedule at command as shown here

at commands with now

To run this script on 10:15 AM you need to schedule at command as shown here

at command with time

To check the status of your jobs, so you can see if it will work, run the following job queue command:

atq

If there's a problem with the job, you can remove it with the atrm command. In this example you would remove job number 4 with the following command:

atrm

Securing At daemon

You may not want everyone to be able to run a job in the middle of the night. If your system have important security data, someone may download important data or worse, and it could be done before you discover the security violations.

Two files are used to control the behavior of at daemons

  • /etc/at.allow If present then only users those name are in this file can use at daemons
  • /etc/at.deny If present then only user those name are in this file will not be able to use at daemons apart from these user all other can use at daemons
  • If both files are not present then only root can access at daemons

For example create two user Vinita and nikita

useradd

These files are formatted as one line per user; add user vinita to at.allow

at allow

To test login on other terminal from user vinita and schedule job from at commands

at permit vinita

Now login on other terminal from nikita and schedule job form at commands

deny nikita