Friday, December 9, 2016

at: Scheduling Processes

at: Scheduling Processes 


Scheduling Processes 


Using the at Daemon

Using at is a great way to schedule a process to run once sometime in the future. The at service is a system daemon (called atd) that runs in the background on your system.


Most Linux distributions install this service for you during the initial installation of the system. If not, you may need to install it manually from your installation repository using the rpm utility.



If your distribution uses init, then the startup script used to start the atd daemon is located in your init script directory, which should be either /etc/init.d or /etc/rc.d/init.d, depending on your particular distribution. The name of the script is atd.


Before attempting to use at, you need to make sure the atd daemon is running. You can do
this by entering

rcatd start 

at the shell prompt. You can also run the script file with its full path followed by start at the shell prompt to accomplish the same task. Make sure the atd daemon will start automatically on boot using the

insserv or chkconfig 

command.


If your distribution uses systemd instead of init, you start the atd daemon by entering

systemctl start atd 

at the shell prompt as root.



At this point, you need to specify which users can and which users cannot create at jobs. This can be done by editing the following files:


/etc/at.allow 
   Users listed in this file are allowed to create at jobs.


/etc/at.deny 
   Users listed in this file are not allowed to create at jobs.



To use at to schedule a command to run at a future time, complete the following:


1.At the shell prompt enter

  at time 

  The at daemon is very flexible as to how you specify the time value in this command.

  [Observe the syntax shown in Table 13-2, p485 ]



After you enter the at command and a time value from Table 13-2, the at> prompt is displayed,
as shown here:


openSUSE:~ # at now +10 minutes 
warning: commands will be executed using /bin/sh
at>



2.At the at> prompt, enter the command(s) you want at to run for you. It’s important to 
  note that if your commands display output on the screen from the shell prompt, you 
  won’t see the output when the commands are run by at. You have two different options
  for viewing the output. First of all, if you don’t specify any alternative, at will e-mail the 
  output to your local user account.

  Alternatively, you can also redirect the output to a file. You learned how to do this earlier
  in this book. For example, if you wanted to run the tail /var/log messages command in the
  future with at, you could enter

  tail /var/log/messages > ~/atoutput.txt 

  at the at> prompt to send the output from the command to a text file named atoutput.txt in your home directory.



3.Press enter if you want to add additional commands. You can run multiple commands within the same job. Each command   should be on its own line.
 


4. When you’re done entering commands, press
   ctrl-d 

   When you do, the at> prompt will  disappear, the job will be scheduled, and a job number will be assigned, as    shown here:

  openSUSE:~ # at now +10 minutes
  warning: commands will be executed using /bin/sh
  at> tail /var/log/messages > ~/atoutput.txt
  at> <EOT>
  job 3 at 2011-04-02 08:57
  openSUSE:~ #



Once you’ve configured the job, you can use the

atq 

command to view a list of pending at jobs.


This is shown next:


openSUSE:~ # atq
3 2011-04-02 08:57 a root



If you are logged in as a regular user, the atq command will display only the jobs associated 
with the current user account.

If you’re logged in as root, then atq will display all pending jobs for all users.


 If you need to remove a pending job from the list, you can use the

atrm job_number 







LX0-104 Exam Objectives (L)

No comments:

Post a Comment