Re: cron

LuKreme <kremels-/[email protected]> Thu, 23 Feb 2012 22:37:35 -0700
Newsgroups gmane.comp.macosx.admin
Message-ID <[email protected]>
On 23 Feb 2012, at 14:06 , János Löbb wrote:

> Folks,
> 
> I am sure I was sleeping at the wheel regarding this issue, so I need a hit on my neck to the right direction.
> 
> I have this little crontab entry:
> bml0041:shell_script janos$ cat del_from_sequoia.crontab 
> 10 * * * * /Volumes/Data/PROJECTS/Sysmon/shell_script/del_from_sequoia.ksh > /dev/null 2>&1
> 
> That is I want at 10 minutes after the hour to execute a shell script.
> 
> The script is this:
> 
> bml0041:shell_script janos$ cat del_from_sequoia.ksh
> #!/bin/bash
> #
> scp [email protected]:/prod2/ase15/sysmon/sysmonlogs/*.log /Volumes/Data/PROJECTS/Sysmon/sysmsa/
> 
> ssh [email protected] "find /prod2/ase15/sysmon/sysmonlogs -name '*.log' | xargs rm "
> 
> That is first I copy over some files from a remote server to my local machine followed by deleting the files on the remote server.
> 
> If I do these two commends on the local machine at the CLI, both works fine.  However executing them via cron is a no go, that is nothing happens.

Neither ssh nor sep like running without a terminal session attached.

> Now, I see in man crontab, that it wants me to use launchctl and I looked its man page too, but I am not seeing how could I schedule the execution of this script with launched.

Scheduling in Launchd is quite simple.

<key>StartInterval</key>
<integer>1500</integer>

To run every 1500 seconds.

<key>StartCalendarInterval</key>
<dict>
  <key>Hour</key>
  <integer>14</integer>
  <key>Minute</key>
  <integer>0</integer>
</dict>

to run at 2pm

<key>StartCalendarInterval</key>
<dict>
  <key>Minute</key>
  <integer>10</integer>
</dict>

Run at 10 after, every hour.

You can also set it to run when a file is changed, when a volume is mounted, or when a file is added to a folder.

launched should not have any problem executing your ssh commands as cron does, though. Should work just fine.

NB: I do not use StartCalendarInterval on any of my jobs, I just set them for the approximate delay I want them to run. At least back in 10.4, StartCalendarInterval was quite buggy. 

Check man 5 launchd.plist and note that *missing values are considered to be wildcards*, so if you leave off the minute, it will run every minute, if you leave off the hour, every hour, if you leave off the day, ever day, etc.


-- 
I don't want to sell anything, buy anything, or process anything as a
career. I don't want to sell anything bought or processed, or buy
anything sold or processed, or process anything sold, bought, or
processed, or repair anything sold, bought, or processed. You know, as a
career, I don't want to do that.