Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automation and Security

I need to schedule a daily script to run on my X-Serve, Snow Leopard, but my server is at a server hosting site. I need to be able to lock the server somehow while allowing this script to run. I have tried using the screensaver to lock the server while using ical to schedule the script to run, I have tried using keychain to lock the computer while using crontab to schedule the script to run, and every combination I can think of. I would think this would be a common need, so I am hoping someone has an easy solution to this problem. I have been able to launch the script with ical and automator or ical and applescript while the computer is not locked, but the server really needs to be secure as well.

Any suggestions on how to merge security and automation with an apple server?

Mac OS X (10.6.4)

Posted on Oct 16, 2010 6:34 PM

Reply
6 replies

Oct 16, 2010 8:20 PM in response to Douglas Mott

The proper way is to use launchd.. there is a gui to create/mange launchd tasks, it's called 'lingon'. Lingon isn't updated anymore, but it's still relevant and a handy way to quickly create a launchd task.

but that said... my preference for simply running a script at a specific time or repeating interval is to use the old fashioned method 'cron'


- what kind of script is it? (bash, applescript, etc)
- when should it run, it could run a specific days/times, repeating intervals or when something happens (like when items are added to a folder).

Oct 17, 2010 8:38 AM in response to UptimeJeff

There are actually a few scripts that i need to run at different intervals. One is a simple applescript that performs a backup the other is a php script that gathers data from a txt log file. Each of these need to be every day.

Since I posted this question I began reading about launchd. Thank you I will look more into Lingon. So by using launchd I will be able to perform these scheduled tasks while the server remains in a secure/locked state?

Oct 17, 2010 10:58 AM in response to Douglas Mott

correct.. the scripts can run without a user logged in.

cron is a really easy way of doing this.... an example, I would add entries such as this to /etc/crontab

# this will run myscript as root user every day at 3:00am and send output nowhere
0 3 * * * root /path/to/myscript > /dev/null

# this will run myscript every 10 minutes as root user with output sent to myscript.log
*/10 * * * * root /path/to/myscript >> /var/log/myscript.log

Here is one of many tutorials on crontab
http://www.tutorial5.com/content/view/95/51/

that said.. launchd has it's advantages... here's a decent article
http://www.devdaily.com/mac-os-x/mac-osx-startup-crontab-launchd-jobs

But.. even with the advantages of launchd- I still prefer crontab to kick off scripts on schedule/intervals.

Jeff

Oct 17, 2010 12:43 PM in response to UptimeJeff

Okay, I have now been able to get launchd to run the app, but still not able to have it run while the computer is locked. Having seen the latest reply, I have gone back to attempting to use cron to run the app. I have tried this several ways. Here is an example:

17 * * * * open /users/test/desktop/testlaunch.app

To test this feature I have a sample Filemaker Pro Database that I have this app open that runs a script that creates a new record in a test table with a timestamp and then it closes Filemaker. If I remain logged in this scenario will work, but if I log out, start the screensaver, or lock the screen through the keychain the app will not run.

I have created a txt file that I use to load crontab. To do this I saved the test.txt file on the desktop, navigate to the desktop in terminal and type "crontab test.txt". Since the last reply to this question I have tried "sudo crontab test.txt". I can then see the schedule when I type "sudo crontab -l" so it is scheduled to run from the root account. But nothing seems to work. Am I doing something wrong? Thanks for all of the help so far.

Oct 17, 2010 1:37 PM in response to Douglas Mott

this entry will run on 17 minutes past every hour.
the user 'open' will launch testlaunch.app

You probably don't have a user named 'open' so this will error out.

If you have a user logged in, but the screen is locked, then try that user, something like:
17 * * * * myuser open /users/test/desktop/testlaunch.app

If you meant it to run at 5:00pm (guess from the 17) then it should start with
0 17 * * *


I'm not sure if this filemaker app you are trying to run requires a logged in user or not.... so I can't tell you if this particular task will do you what you want.

if you want to test the cron syntax, try something very simple like

0 17 * * * * root say hello
the above would speak the word hello at 5:00pm

Automation and Security

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.