12

I am trying to make the at bash command to run, but it is not working for me. I can add a job to the queue, but it is not run when the time is up. What am I doing wrong?

hpek@melda:~$ cat /usr/lib/cron/at.deny 
hpek@melda:~$ atq
hpek@melda:~$ at now +2 minutes
echo TTTEEEST
job 12 at Sun May  6 02:09:00 2012
hpek@melda:~$ date
Sun May  6 02:10:24 CEST 2012
hpek@melda:~$ atq
12  Sun May  6 02:09:00 2012
hpek@melda:~$ 

UPD2021.08.06 atd was removed in MacOS 11.5.2 (or earlier)

$ sudo find / -name atd -print 2>/dev/null
$ 
Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66
hpekristiansen
  • 1,030
  • 3
  • 17
  • 35
  • Are you running a [mandatory access control](http://en.wikipedia.org/wiki/Mandatory_access_control) tool such as [AppArmor](http://wiki.ubuntu.com/AppArmor/), [SELinux](http://en.wikipedia.org/wiki/Security-Enhanced_Linux), [TOMOYO](http://tomoyo.sourceforge.jp/index.html.en), or [SMACK](http://schaufler-ca.com/)? Any of these could restrict `cron(8)` from running jobs or saving output. – sarnold May 06 '12 at 00:51
  • I have not mentioned that I am on a mac - because I did not think that it was important. I now believe that the answer can be found here: http://superuser.com/questions/43678/mac-os-x-at-command-not-working . I will soon delete this question, because it is a duplicate. – hpekristiansen May 06 '12 at 01:09
  • Ha! Thanks for the feedback; I wish there were an easy way to close-as-duplicate of content on another site, because the phrasing of this question is good and may help someone else find the problem in the future. – sarnold May 06 '12 at 01:10
  • at daemon is running? – Leonardo Hermoso Jan 31 '17 at 00:10
  • @Leonardo Hermoso: Please read answers. – hpekristiansen Jan 31 '17 at 00:24
  • Maybe cout this: [sleep util specific time/date](https://stackoverflow.com/a/19067658/1765658) answer your need! – F. Hauri - Give Up GitHub Sep 04 '21 at 13:41
  • Duplicates https://superuser.com/questions/43678/mac-os-x-at-command-not-working that has answers that are still applicable to macosx 11 – Anton Tropashko Sep 06 '21 at 06:37
  • A duplicate of https://superuser.com/questions/43678/mac-os-x-at-command-not-working muru's answer with launchctl to the rescue – Anton Tropashko Sep 06 '21 at 06:39
  • 1
    https://unix.stackexchange.com/questions/478823/making-at-work-on-macos/478840#478840 worked for me on macOS 11.2.1 – HappyFace Sep 06 '21 at 10:13
  • thanks. it was working without full disk access though. don't remember what I did but It runs now. – Anton Tropashko Sep 08 '21 at 12:12

7 Answers7

7

It is working fine. It's just that commands running with at don't write their output to the terminal that you called it from.

Try:

at now +2 minutes
echo TTTEEEST > new_file_test

You'll see the file appear in two minutes.

Paul
  • 139,544
  • 27
  • 275
  • 264
  • How about if you give an absolute pathname? Probably `at(1)` is executing the script either in your home directory or its home directory. (Mine executes in my user's home directory; tested with `/bin/pwd > /tmp/pwd`.) – sarnold May 06 '12 at 00:41
  • @sarnold: No - it is not working. Is your job removed(from `atq`) when the time is up? – hpekristiansen May 06 '12 at 00:44
  • @Hans-PeterE.Kristiansen Yup, you're right. Sorry for the wrong answer. – Paul May 06 '12 at 02:10
5

Take a look at /var/at/jobs and see if your at jobs are listed there. (It may be a different directory based upon OS).

By default, at isn't enabled on most systems. In order for at jobs to actually get executed, the atrun command must execute.

This command is executed either through launchd or through the cron depending upon the system.

The exact mechanisms are different from system to system, so you'll have to read all the various manpages on at, atrun, etc. to verify if at is really enabled on your system, and whether you have permissions to run at jobs. There's normally both an ant allow and an ant deny file on your system, so you need to check both. You must be both in the allowed file, and also not in the deny file.

On top of that, you have to make sure that at is even enabled on your system (due to security concerns, it is usually disabled).

David W.
  • 105,218
  • 39
  • 216
  • 337
1

Check your mail:

   An at - or batch - command invoked from a su(1) shell will
   retain the current userid.  The user will be mailed standard
   error and standard output from his commands, if any.  Mail
   will be sent using the command /usr/sbin/sendmail.  If at is
   executed from a su(1) shell, the owner of the login shell
   will receive the mail.
sarnold
  • 102,305
  • 22
  • 181
  • 238
1

I've found this here

First make sure that the at daemon is running using a command like this:

# ps -ef | grep atd
root 8231 1 0 18:10 ? 00:00:00 /usr/sbin/atd

If you don’t see atd running start it with this command:

# /etc/init.d/atd start
Jekis
  • 4,274
  • 2
  • 36
  • 42
0

To analyze at(d) execution problems it may help to

  1. Check /etc/at.allow and /etc/at.deny for existance and contents (see man at.allow)
  2. Check owner and access rights of the atd spool directory (/var/spool/cron/atjobs, daemon:daemon, 770 on Ubuntu)
  3. Check if atd daemon is running (systemctrl -a | grep atd on Ubuntu)
  4. tail -f /var/log/syslog (at execution time)
  5. journalctl -b | grep atd (found that here, contains further hints)

The "Permission denied" error may also be caused by limited number of logins defined (for the at running user) in /etc/security/limits.conf.

Michael Besteck
  • 2,415
  • 18
  • 10
  • antonsmbp:tango atropashko$ journalctl -b | grep atd -bash: journalctl: command not found antonsmbp:tango atropashko$ sudo journalctl -b | grep atd sudo: journalctl: command not found – Anton Tropashko Sep 03 '21 at 17:22
  • @AntonTropashko which OS are you trying on? – Chen A. Sep 08 '21 at 05:58
0

I too faced same issue with echo when used along with at command. But if you try to redirect the output using > or >> then it works perfectly. Also try some other system commands like reboot, ls > some_text_file etc to make sure at command is working. Else try sudo systemctl enable --now atd to enable at daemon

JOSEPH BENOY
  • 149
  • 1
  • 6
0

Conclution First: atrun or atd daemon is not running, causing this problem.

Guideline to solve your case:

  1. check at mannul by man at first. In my case, I(macos 10.13.6) found following info:
 Note that at is implemented through the launchd(8) daemon periodically invoking atrun(8), which is disabled by default.  See atrun(8) for information about enabling atrun.
  1. check atrun mannul by man atrun, I found :

The atrun utility runs commands queued by at(1). It is invoked periodically by launchd(8) as specified in the com.apple.atrun.plist property list. By default the property list contains the Disabled key set to true, so atrun is never invoked.

  1. Execute the following command as root to enable atrun: launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
ablian
  • 193
  • 1
  • 5