Getting started with cronjobs on Mac

I am trying to get to know cron jobs, and I think I am getting a basic idea (planning, syntax, etc.). But I can’t understand how it works on my Mac with a terminal - where exactly do I find Krontab? How do I refer to script paths?

What I'm trying to do is click on the php script on the remote computer ( http: // ... ) - Is this possible at all?

+6
terminal cron crontab macos
source share
6 answers

To get started with launchd (instead of cron), you first want to create an empty .plist file, such as local.mytask.plist , and put it somewhere. ~/Library/LaunchAgents is probably a good place. Open it in a text editor and copy to the code below

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <false/> <key>Label</key> <string>local.mytask</string> <key>ProgramArguments</key> <array> <string>/opt/local/bin/wget</string> <string>http://someserver/somepage.php</string> </array> <key>StartInterval</key> <integer>300</integer> <key>RunAtLoad</key> <true /> <key>StandardErrorPath</key> <string>/dev/null</string> <key>StandardOutPath</key> <string>/dev/null</string> </dict> </plist> 

Then "activate" the file from the command line:

 sudo launchctl load /Users/my_username/Library/LaunchAgents/local.mytask.plist 

To make it load automatically, create a ~/.launchd.conf with the same line (minus sudo launch )

 load /Users/my_username/Library/LaunchAgents/local.mytask.plist 

The above instructions were copied from www.davidlanier.com and sent here for reference.

+4
source share

Type crontab -e to change your cron table and crontab -l to display the current contents. Type man 1 crontab for more information on this command and man 5 crontab for more information on the cron table file format.

For example, to load the stackoverflow page every day at 10:00, run crontab -e , enter this line, and then save / close. The output will be written to a file in your home directory.

 0 10 * * * /usr/bin/curl -s http://stackoverflow.com > ~/stackoverflow.html 
+8
source share

In the event of an unforeseen incident that someone else fighting a cron on Snow Leopard stumbles over this, I will delve into this old stream.

Yes, startd should replace cron, but in fact it cannot do certain things cron can.

Cron is not well integrated. If he sends a message, he gets to / var / mail / user _name, which, of course, Apple Mail knows nothing.

crontab -e says that "the temp file must be edited in-place." Obviously, vim is not compatible with vi. Then you can do crontab "</tmp/crontab.whatever" (look in / tmp and see what name is actually used), and it will be in the right place and, assuming that you did not make a typo, it will work.

Yes, it took a while to figure this out :(

+4
source share

launchd is powerful, but you really don't want to write plist yourself. Get Lingon . It is an open, well-designed graphical interface for creating and managing system startup tasks.

+2
source share

Cron has been replaced by launchd since 10.4. You should probably write your assignments if you are not planning to transfer them to Linux / Unix systems at some point.

If you decide to go with cron anyway, try crontab -e or sudo crontab -e . This will give you different crontab files, the first for the user you are currently using and the last for the root user.

Clicking a URL can be done in many ways. Depending on the local script that you use to β€œhit”, you can use some of the built-in methods / classes of the language. For example, a Ruby script will use net / http , but you can also try spinning around if you just write a bash script. Do man curl to find out more, but the main command is just curl http://google.com .

+1
source share

You no longer want to use cron. As others have already noted, it has been replaced by launch, and launchd will undoubtedly become the future in Mac OS X.

MacTech Magazine has recently been making a series of launch articles, and I highly recommend reading them. I know that I learned a lot.

September, 2009 (Volume 25, Issue 9) 25.09 MacEnterprise: launchd for lunch

October 2009 (Volume 25, Issue 10) Snow Leopard, Launchd, and Lunch More starter recipes and look at the changes in Snow Leopard

Other articles appeared on MacTech, and I would suggest looking for their site.

0
source share

All Articles