command: at

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

  1. gcawood

    gcawood Administrator Staff Member

    Joined:
    Oct 28, 2011
    Messages:
    49
    Likes Received:
    19
    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

    Joined:
    Nov 11, 2011
    Messages:
    87
    Likes Received:
    3
    Nice command. I don't see what circumstances this would be useful in though, any hints?
     
  3. carbon333

    carbon333 New Member

    Joined:
    Feb 16, 2012
    Messages:
    87
    Likes Received:
    7
    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

    Joined:
    Apr 20, 2012
    Messages:
    115
    Likes Received:
    3
    When setting up cron jobs at time intervals.
     
  5. DaSt1986

    DaSt1986 New Member

    Joined:
    Jul 12, 2013
    Messages:
    15
    Likes Received:
    2
    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

    Joined:
    Oct 31, 2013
    Messages:
    1
    Likes Received:
    0
    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

    Joined:
    Jul 13, 2013
    Messages:
    6
    Likes Received:
    5
    at is really very useful command, but i think admin use cron is just because of anacron
     
  8. GeeezerRTT

    GeeezerRTT New Member

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

    ZHANG/ZHIKUN New Member

    Joined:
    Aug 22, 2014
    Messages:
    27
    Likes Received:
    2
    good command.
     
  10. MelRay

    MelRay New Member

    Joined:
    Apr 22, 2014
    Messages:
    23
    Likes Received:
    6
    Interesting thanks!
     
  11. icehouse15

    icehouse15 New Member

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

    Videodrome Active Member

    Joined:
    Nov 17, 2013
    Messages:
    328
    Likes Received:
    132
    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?
     
  13. dtse9

    dtse9 Member

    Joined:
    Jun 19, 2015
    Messages:
    81
    Likes Received:
    11
    no, it will return a error,. because the main function is usually int main(int argc, char *argv)(i'm not sure.)
     

Share This Page