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`;
$pid_num =~ s/[\d.]+/;
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)

Just wondering what anyone thinks of this code. Is there an easier way?

Also, I have trouble where the "top | grep iTunes" line doesn't work... 
I'm guessing it's because top continuously updates without quitting 
automatically, so it can't output anything to grep until I kill it, but 
in that case I've killed the entire process, including grep. Doesn't 
work when I use it in perl or the command line.

tia,
Chris Garaffa
[EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to