Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I tried to use at to schedule a job running at a specific time. I have a Mac computer. For example, I tried to test this by for the following at in Terminal:

at now + 1 minute
echo 'Test at'
<EOD>

after more than 1 minute, I did not see the echo out. After I type in the following command:

at -l

I did not see any jobs, but I got message saying I have a mail. I went to my mail by mail command. I did see one message and I typed 1. I saw my job output is in the mail.

My first question is that I am not sure if this the default behaviour for at command or not. Is there any way change this behavour and how to change it direct the result to where if possible.

My understanding is that if my scheduled job has any message and the output message will be send back to my mail. My next related question is that I am not sure where does the scheduled job run? In a background? I could not find it by using fg or bg command.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

It is indeed the default behavior of at as stated in man at:

The user will be mailed standard error and standard output from his commands, if any. Mail will be sent using the command sendmail(8). If at is executed from a su(1) shell, the owner of the login shell will receive the mail.

For a different behavior you can invoke at like this:

$ at now + 1 minute 
$ echo "test at" > /dev/ttys000
$ <EOD>

Which will redirect STDOUT to the terminal ttys000. You need to replace /dev/ttys000 with the corresponding device file of your terminal, which you can determine by running the following command:

$ tty

Scheduled jobs are executed in their own shell (see man at for more details), such that bg won't list them. To see a list of scheduled jobs, you might want to try atq or at -l

share|improve this answer
    
I commented earlier that instead of using the tty command to look up the current tty, you could use the generic /dev/tty which always represents the current working terminal. This is true, but I now think that this won't work for at commands since they are run in an environment without a controlling terminal. You should revert back to your original advice to find the current terminal and redirect to that. Sorry for the misinformation. –  nagul Sep 20 '09 at 0:52
    
You're right nagul, thanks! –  dblu Sep 20 '09 at 0:59
    
The mail address is a UNIX mail default address. Is there any way to redirect to my iMail which could be gmail or my internet provider email account? Another way may be I have so set up my local mail to redirect mails to my iMail box. Or can I set up my iMail to open my local mail box? –  David.Chu.ca Sep 20 '09 at 1:16

Yes, mailing the user who invoked the at command is the default behaviour.

From the at man page:

Since the commands run in a separate shell invocation, running in a separate process group with no controlling terminal, open file descriptors, traps, and priority inherited from the invoking environment are lost.

As a result of the above, there is no easy way to communicate the output of the commands. You can of course redirect the output to a file, or use an alternate mechanism to communicate the output, as part of the commands.

If you don't see the scheduled job, it's because there's an atd daemon running on the system which receives and executes the at jobs. On a Mac, these may be handled by the launchd daemon which is Apple's all-in-one replacement daemon:

The launchd daemon is essentially a replacement for init, rc, the init.d and rc.d scripts, SystemStarter (Mac OS X), inetd and xinetd, atd, crond and watchdogd. Apple has stated that it intends to eliminate all of the aforementioned services in favour of launchd

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.