Perform command at time


Uses of "at" command to do job at specific time:
 
01. For example,  your office declared the internet connection will be off after 8 pm, but you've to leave office now. don't worry ! just issue the following command and get out of your office. If you use squid type the following command:

# at 20:00
at> service squid start
(Press CTRL+D to save)

If you use your linux box as router:
# at 20:00
at> echo 1 > /proc/sys/net/ipv4/ip_forward

02. When I take exam in my class, the questions and answer sheet is available in my webserver. If the exam starts from 10.00 am and ends at 11.00 am.
# at 10:00
 1 / 5Perform a command at specific time
 
at> service httpd start
CTRL+D

# at 11:00
at> service httpd stop
CTRL+D

03. When the last date of submission a project through ftp is 06:00 pm, 11th June, 2011
# at 18:00 06/11/2011
at> service vsftpd stop
CTRL+D
Two more "at" related utilities
atq : show the current pending jobs
 2 / 5Perform a command at specific time

atrm: remove any pending job
While "at" command is used for performing a command (or run a script) once at a specific time,"cron" is used to perform the job repeatably at a specific time. For example, If your office decided to keep your internet from 08.00 am to 6.00 pm everyday, you need to do the
followings:
 
01. Create two executable scripts which will be used to stop squid and start squid
# vi /usr/sbin/stopsquid
------------------------------------------
#! /bin/bash
service squid stop
------------------------------------------
# chmod 755 /usr/sbin/stopsquid
 3 / 5Perform a command at specific time

# vi /usr/sbin/startsquid
 
------------------------------------------
#! /bin/bash
service squid start
------------------------------------------
# chmod 755 /usr/sbin/startsquid
02. run the corn at 08 hours and 18 hours

# crontab -e

00 18 * * * /usr/sbin/stopsquid
00 08 * * * /usr/sbin/startsquid

# service crond restart
 4 / 5Perform a command at specific time

For more information about corn: manpage of crontab, crond

No comments: