3

I use cron to schedule things in Linux, but recently I discovered the "at" command.

sudo apt-get install at

I don't understand the scope from which this command operates:

  • How would you schedule a command with at, that normally requires admin privileges?
  • What is the working directory (pwd) of a command scheduled with at?

Additionally, everything I've tried so far, didn't achieve what I was trying to do.

For example, I tried to launch gedit one minute from now:

echo "gedit" | at now + 1 minute

I waited a minute, and nothing happened.

I tried to turn off my monitor one minute from now:

echo "xset dpms force off" | at now + 1 minute

I waited a minute and nothing happened.

If I can't get "at" to reliably perform a task one minute from now, how can I be certain that it will perform something I tell it to do tomorrow and beyond?

What am I missing here?

v2r
  • 9,367
  • 11
  • 49
  • 52
Lonnie Best
  • 2,174
  • 2
  • 32
  • 42

1 Answers1

6

Try instead:

~$  at now + 1 minute
at> ls -ahl > /tmp/at_test
at> ^D

You will find /tmp/at_test after command executed.

If you want to run some GUI app you should specify DISPLAY variable; Use echo $DISPLAY to find out you display

~$  at now + 1 minute
at> DISPLAY=:0 gedit
at> ^D

Piping is also ok:

echo "DISPLAY=:0 gedit" | at now + 1 minute
Lonnie Best
  • 2,174
  • 2
  • 32
  • 42
Dan
  • 6,715
  • 5
  • 26
  • 43
  • 1
    Not working. I'm getting this error `warning: commands will be executed using /bin/sh` first then the `at>` prompt. Anything I type then doesn't run. – Parto Jun 16 '14 at 16:55
  • 1
    ^D means control+D, right? I tried this and the output was "job 5 at Mon Jun 16 11:54:00 2014". However, gedit never launched. – Lonnie Best Jun 16 '14 at 16:56
  • 3
    @dan08, `at` does not export `DISPLAY` variable. @LonnieBest, you can run gedit using this: `at now + 1 minute` `DISPLAY=:0 gedit` `^D` – c0rp Jun 16 '14 at 17:48
  • echo "DISPLAY=:0 gedit" | at now + 1 minute – Lonnie Best Jun 17 '14 at 20:24