Hot answers tagged

35

Bernhard's reply is correct: in multi-user systems, the ability to execute heavy programs at some ungodly hours of the night is especially convenient, for both the person submitting the job, and his coworkers. It is part of "playing nice". I did most of my Ph.D. computations this way, combining the script with the nice command which demoted the priority of ...


21

Commands run by at don't run in the terminal where they were registered. This wouldn't make sense in general: the terminal might not exist any more, or it might be in use by a different user. You may even have logged out by the time the command runs. Output from an at command is sent to you by email. That's local Unix email, not whatever external POP or ...


16

I use the at command when I need to do some heavy processing on data, which I want to have executed during the night, when I am not behind my computer. Of course I could start the process just after I leave, but this is something I tend to forget. The result of the command is not different from regularly execution of the script or command.


15

Because at does not execute commands in the context of your logged in user session. The idea is that you can schedule a command to run at an arbitrary time, then log out and the system will take care of running the command at the specified time. Note that the manual page for at(1) specifically says (my emphasis): The user will be mailed standard error ...


15

You can run this command to remove all the jobs at the atq for i in `atq | awk '{print $1}'`;do atrm $i;done


11

Assuming you're on Linux, the output of atq always has the date in the same format. Sort the fields in the appropriate order, taking care to declare which ones are numbers or month names. Make sure to use an English locale for the month names since that's what atq uses. atq | sort -k 6n -k 3M -k 4n -k 5 -k 7 -k 1 # year month day time queue id


10

You could do something like this: for i in $(atq | cut -f 1); do atrm $i; done


10

When you have questions such as this always consult the man pages. They can be very enlightening. What it does excerpt from at man page NAME at, batch, atq, atrm - queue, examine or delete jobs for later execution DESCRIPTION at and batch read commands from standard input or a specified file which are to be executed at a later ...


10

Bash functions are exported via the environment. The at command makes the environment, the umask and the current directory of the calling process available to the script by generating shell code that reproduces the environment. The script executed by your at job is something like this: #!/bin/bash umask 022 cd /home/nick PATH=/usr/local/bin:/usr/bin:/bin; ...


8

From the cron man page: When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists). The children copies of cron running these processes have their name coerced to uppercase, as will be seen in the syslog and ps output. So you should check ...


8

You could use the command 'at' at now +4 hours -f commandfile Or at now +$((($RANDOM % 10)+2)) hours -f commandfile


7

Under Linux, at always warns you that it will execute the specified commands with /bin/sh, rather than your favorite shell. You cannot suppress this message, it's hard-coded in the source code. The command you pass is interpreted by /bin/sh. This command can be the path to a script if you like; then /bin/sh will execute the script program, causing the ...


7

A restart of the atd service did not reset the job id as we suspected: Example some test submissions $ at -f test.bash now job 105 at Mon Sep 23 20:04:00 2013 $ at -f test.bash now job 106 at Mon Sep 23 20:04:00 2013 double checking the spool dir $ sudo ls -l /var/spool/at/spool/ total 0 a restart of atd $ sudo /etc/init.d/atd restart Stopping atd: ...


6

The program that constitutes the at job is a child of the atd (at daemon) process, not of the shell where you run at. So it does not inherit the current shell's environment. The at system arranges to copy the environment (and the working directory and a few more obscure thing), but it omits a few variables. In particular, the DISPLAY variable is not copied ...


6

Since at defaults to reading from standard input, you can just do this: echo /path/to/script argument | at 17:45


6

You can execute batch jobs in UNIX / Linux using any one of the three commands — at, batch or cron. Schedule an at job using specific date and time Syntax: $ at time date For example, to schedule a job at 11 am on May 20, use the following at command. $ at 11 am may 20


6

Option 1 Schedule your job in cron to run every hour (or every other hour), but prefix the job with something like this (presuming you have SHELL=/bin/bash in your crontab): [ $[RANDOM % 12] -eq 0 ] || exit 0; YOUR_JOB_HERE Then there will be an approximately* one in twelve chance of the job running each time its scheduled. Option 2 Schedule a cron job ...


5

CentOS at configuration file is in /etc/sysconfig/atd according to the man page, the mail notification is as follows: If the file /var/run/utmp is not available or corrupted, or if the user is not logged on at the time at is invoked, the mail is sent to the userid found in the environment variable LOGNAME. If that is undefined or empty, ...


5

As @MichaelKjörling has explained it any output that's produced by your at job will be captured and sent to you via email. If you don't have a running MTA - Mail Transfer Agent on your box then the email may be in limbo and you'll not know that at is even attempting to do this. A MTA, is a program such as sendmail or postfix that can "deliver" email to an ...


5

Because that's not how the at command works. at takes the command in via STDIN. What you're doing above is running the script and giving its output (if there is any) to at. This is the functional equivalent of what you're doing: echo hey | at now + 1 minute Since echo hey prints out just the word "hey" the word "hey" is all I'm giving at to execute one ...


5

You could use a program such as rlwrap (readline wrapper) for this: rlwrap at now Further reading: hanslub42/rlwrap (github) * HOW TO USE IT: If $ <command> <args> doesn't let you use arrow keys to edit input, or if you just want decent input history and completion, try: $ rlwrap [-options] <command> <args>


4

you can achieve running it from a different shell changing the script shebang. Some typical shebang lines: #!/bin/sh — Execute the file using sh, the Bourne shell, or a compatible shell #!/bin/csh -f — Execute the file using csh, the C shell, #!/usr/bin/perl -T — Execute using Perl with the option for taint checks #!/usr/bin/php — Execute the file using ...


4

Depending on your Linux distribution and the kind of installation (minimal, desktop-centric, etc.) at (and atd the at job scheduler daemon) is installed by default or not. To verify it you can issue commands like: $ which at /usr/bin/at $ which atd /usr/bin/atd $ yum whatprovides atd # to get the package name $ yum info pkg-name # to see if it is ...


4

From usr/share/doc/at/timespec, it doesn't look like it. But you can always use date to convert your timestamp, eg: at "$(date --date=@1393419435 +'%D %T')" date takes a timestamp in seconds, so don't forget to trim fractions of seconds if needed.


4

A timestamp (as recognized by at, see the fine manual) must be given: bash-4.1$ echo echo hi | at teatime job 5 at 2016-02-02 16:00 bash-4.1$


4

The | sends the stdout of the left process to the right command. Your sendit function actually sends the mail, but doesn't produce much output on stdout (I actually don't remember what the output of mail is), so the input to at isn't a command to send the mail. Consider that as a user, you would typically have used at like this: at 02:37 May 03 # ...


4

The RedHat (and thus Centos and friends) at and also Debian-derived vintages (as rpm -qi at on RedHat indicates a Debian URL, and also derobert in comments, above) should support a -M option: -M Never send mail to the user. Lacking this, another option would be to suppress output from the job: #!/bin/bash exec >/dev/null 2>&1 ... the ...


3

You can pipe the output of atq to sort and use the k switch (sort via key) and M (month-sort) to list your jobs by date. For example, the default output would look like: atq 5 Mon Dec 10 19:00:00 2012 a jason 6 Tue Jan 15 05:00:00 2013 a jason 4 Thu Dec 6 19:00:00 2012 a jason Piping through sort: atq | sort -r -k3M -k4 6 Tue Jan 15 05:00:00 2013 ...


3

You send ctrl-D like this: send "\004" http://wiki.tcl.tk/3038 http://expect.sourceforge.net/FAQ.html#q54


3

You could use a plain shell script: #! /bin/sh # Usage: setupkill.sh time process. echo /home/jagan/p/killprocess "$2" | at "$1" (Sorry, I don't know expect so this is just a simple workaround.)



Only top voted, non community-wiki answers of a minimum length are eligible