How to use the "at" command to start a shell on macOS

I want to execute some shell script once on macOS.

At first I tried the "at" command in Ubuntu, and that was good. But when I use the same method on MacOS, everything goes wrong.

I typed:

$ at now + 2 minutes ls -al > tmpfile (ctrl+d,EOF) 

The task has been successfully added.

The output of "at -l" is:

 (some other output) 11 Fri Jul 19 15:18:00 2013 

But after 15:18 tmpfile has not been changed.

I want to know how to use the "at" command on MacOS, or is there any other way to execute some shell script at a specific time once (not periodic)

+4
source share
2 answers

Using at

Your use of at displayed correctly. The command will be executed in 2 minutes in the future. The command is not executed repeatedly, so the file is not affected at any time, except for the time that now + 2 minutes is evaluating.

If you are having trouble getting the at command to run commands, make sure that the atrun start agent is activated and running. See man atrun for details .

Better execution of planned teams

If you just want to do something when you log in, then system settings> Users> Login items are preferred. Rename shell scripts with .command as an extension, but if you do. I'm not sure if this is required, but this is what the OS prefers for such scripts.

Otherwise, try cron to provide more control over the job or use launchd , the mac launch daemon (see man launchd and man launchctl ). Read this blog post , which seems to be a good introduction to using the OS X startup control daemon.

Launchd is the preferred way to schedule commands on mac, here I mention only cron , as this might be more familiar if you come from the Linux background. Take a look at this answer for more information on this.

+4
source

I noticed β€œSEE ALSO” on the manual page at:

 SEE ALSO nice(1), sh(1), umask(2), campact(5), atrun(8), cron(8), sendmail(8) 

Atrun (8) provides a solution.

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

After I run this command, and then restart the computer, become available.

+4
source

Source: https://habr.com/ru/post/1492240/


All Articles