> -----Original Message-----
> From: Chris Garaffa [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 04, 2001 12:12 AM
> To: [EMAIL PROTECTED]
> Subject: cron, perl and iTunes
>
>
> Hey everyone,
> Here's a question concerning Apple's iTunes, cron, and tying them
> together with perl.
>
> I want iTunes to be quit at 5:30 AM monday through friday.
> OK, so I know
> how to setup a crontab file. That's no problem. I can get
> iTunes to quit
> (using kill), provided I know its pid. So, I go into top, find iTunes
> and use crontab to edit the file.
>
> Instead of doing this, I'd like to have cron run a perl script which
> looks up iTunes' pid and then kills that pid. Here's a rough
> sketch of
> what I have so far:
>
> #!/usr/bin/perl -w
> use strict;
> $pid_num = `top | grep iTunes`;
Typically you would use ps -ef or similar instead of top
> $pid_num =~ s/[\d.]+/;
This is a syntax error.
> open(CRONTAB, ">/var/cron/tabs/root");
> print CRONTAB <<"endOfCrontab";
> # DO NOT EDIT THIS FILE - edit the master and reinstall.
> # (/tmp/crontab.0000000512 installed on Mon Sep 3 23:51:31 2001)
> # (Cron version -- $FreeBSD:
> src/usr.sbin/cron/crontab/crontab.c,v 1.17
> 2001/06$
> 30 05 * * * kill $pid_num
> endOfCrontab
> close(CRONTAB)
Yikes! Why do this? You're overwriting your crontab (what if I put another
job in the crontab? Too bad, it's gone). What if iTunes is stopped and
restarted manually or there is a system crash before the cron job runs?
Then the pid will be different.
Why not just have the cron job run a script which in turn kills the
iTunes process? Or just use something like this in the crontab entry:
kill `ps -ef | grep iTunes | awk '{print $2}'`
(Note: ps is very system-dependent. Mine is SysV-ish, but yours looks
to be BSD-ish, so make appropriate adjustments).
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]