0

I have created an /etc/crontab file on a Mac OS X that runs a few simple commands. I would like to use the crontab to echo a statement in my terminal, logout from the OS (as if I was to point my mouse to the command Logout), and I am trying to test it by running an echo statement every two minutes. Here is what I have so far:

55 12 * * * echo "Don't forget to log out!! Will be automatically logging out at 12PM Sharpe!!"
* 13 * * * logout
1 * * * * echo "Test"

At that point, I used crontab /etc/crontab to ensure that my user points to the crontab file (which it does) and was able to confirm it by typing crontab -l.. What will i need to do in order to make it so that it echoes in my terminal and have it actually Log out of the operating system at 12 Noon everyday?

  • What version of OS X are you using? – David King Nov 30 '15 at 18:33
  • I am using El Capitan – ryekayo Nov 30 '15 at 18:36
  • 1
    Where would you expect to see the output? The commands are being run in a separate subshell that has nothing to do with what you're actually running yourself. I suggest you post a new question explaining what you are trying to achieve. Your cron is doing precisely what you told it to do, it's just that you told it to do the wrong thing :) – terdon Nov 30 '15 at 18:38
  • 1
    As @terdon implied, this may be an A B Question issue. What is it that you're trying to accomplish that has led you to think that cron is the answer? – DopeGhoti Nov 30 '15 at 18:43
  • 1
    Alias definitions are usually not in place in crons environment, as they are handled by the login shell (usually bash). – DopeGhoti Nov 30 '15 at 18:50
1

If the actual intent is to force a logout of the active user of the system at 1300 every day, try this in the root user's crontab:

0 13 * * * osascript -e 'tell app "System Events" to log out'

If you don't wish to display a confirmation dialog to the user, you can use:

0 13 * * * osascript -e 'tell app "System Events" to  «event aevtrlgo»'
1

The cron table entries are running. They don't run on your active terminal; they run on their own. If your host has a local mail daemon running, you can see the output of the cron jobs which have output (e. g. the echo jobs) in emails sent to your local account by the local mail daemon.

  • Do you mean in /var/mail/<user>? I don't see anything in there that indicates the echo statement has run.. – ryekayo Nov 30 '15 at 18:35
  • If /var/mail/<user> is empty, it's already been delivered. Try running mail in the Terminal. (not to be confused with /Applications/Mail.app) – DopeGhoti Nov 30 '15 at 18:37
1

The use of cron in OS X has been strongly discouraged for a while now in favor of their "better" option called launchd. There are numerous tutorials on how to run jobs with launchd but just to get you started here's one.

http://alvinalexander.com/mac-os-x/mac-osx-startup-crontab-launchd-jobs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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