command: at

Discussion in 'Beginner Tutorials' started by gcawood, Nov 8, 2011.

  1. gcawood

    gcawood Administrator Staff Member

    Messages:
    49
    Likes Received:
    19
    Trophy Points:
    0
    There is a little known command in linux that is very handy when scheduling a task. Normally server administrators prefer using CRON for handling all scheduling. However, CRON is primarily designed for setting up recurring schedules and isn't really the right tool for one time jobs. If you have a server task that needs to be run at a particular time just once, then I suggest using `at`.

    The syntax of at is straightforward.


    COMMAND - DATE

    Here is an example: (run this file at 10am, on December 24th)
    Code:
    at -f /usr/local/bin/reboot.pl 14:45  
    
    where reboot.pl contains
    Code:
    #!/usr/bin/perl
    `shutdown -r now`;
    
    Fancy things you can do with `at`.

    You can get an email when the task is run by using
    -m

    You can change the shell that executes the job
    -c -k -s (C, Korn, Bourne)

    You can specify a file that contains the command to run
    -f
    Code:
    at -f /usr/local/bin/reboot.pl 14:45
    You can list the commands that `at` has in its queue
    -l
    Code:
    at -l
    You can cancel a pending `at` job
    -r
    Code:
    at -r 9
  2. MustangV10

    MustangV10 New Member

    Messages:
    87
    Likes Received:
    3
    Trophy Points:
    0
    Nice command. I don't see what circumstances this would be useful in though, any hints?
  3. carbon333

    carbon333 New Member

    Messages:
    87
    Likes Received:
    6
    Trophy Points:
    0
    Wow, I didn't know about it. Why just not execute at -f shutdown -r now 14:45? Would it work?
  4. Darwin

    Darwin New Member

    Messages:
    115
    Likes Received:
    3
    Trophy Points:
    0
    When setting up cron jobs at time intervals.
  5. DaSt1986

    DaSt1986 New Member

    Messages:
    15
    Likes Received:
    2
    Trophy Points:
    3
    It could be VERY usefull if you're configuring your iptables firewall over SSH. I used a cronjob when I was doing this to remove all rules from the firewall at a specific time so I was sure I could relogon after a while when I made a mistake and blocked SSH. Using a cronjob worked fine, but at would have been more usefull.
  6. Brian Egendorf

    Brian Egendorf New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    This kind of reminds me of an if/than statement...except, its not so much conditional as event based.. Kind of like the difference between, "If you want to see me at 6, then go the the Library", and "Be at the Libray at 6PM!"
  7. jadhav.sudeep

    jadhav.sudeep New Member

    Messages:
    6
    Likes Received:
    5
    Trophy Points:
    3
    at is really very useful command, but i think admin use cron is just because of anacron
  8. GeeezerRTT

    GeeezerRTT New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    What is the connection between December 24, at 10 AM and the entry 14:45???
  9. ZHANG/ZHIKUN

    ZHANG/ZHIKUN New Member

    Messages:
    20
    Likes Received:
    2
    Trophy Points:
    3
    good command.
  10. MelRay

    MelRay New Member

    Messages:
    8
    Likes Received:
    2
    Trophy Points:
    3
    Interesting thanks!
  11. icehouse15

    icehouse15 New Member

    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I use it often to run long compile(make) jobs--just in case vpn decides to reset, etc.
  12. Videodrome

    Videodrome Active Member

    Messages:
    214
    Likes Received:
    80
    Trophy Points:
    28
    If I was logged into a Home Server by SSH and started a download with wget, and I logged off before the download finished, would the download be interrupted as if the "Job" was lost?

    Could using AT be a way to tell a home server to do something like this without having to stay connected? Just issue the instruction to do At a certain time and log off?

Share This Page