Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

REGEXP in perl questiion



Ok, I admint it's lazy but could someone give me a regular expression in 
Perl that would do the following? (I've tried for the last hour but I'm not 
very good at regular expressions it seems).

I have strings like the following:

Subject: Cron <root@example.com> /root/AdminScripts/NSH.sh
Subject: Cron <root@example.com> /usr/bin/rsync -avzr --delete 
/home/httpd/html/top40/* 10.0.1.53:/home/httpd/html/

I want to extract the name of the program that cron started, without the 
switches if any.

I've tried this but it's greedy and doesn't extarct *just* the prog name but 
also the switches ... I tought the " .*?" would cause lazy expansion but 
it's not working as I had hoped.

if ( $_ =~ /^Subject: /) {
  if ($_ =~ "Cron") {
    $CRON_EMAIL = 1;
    /^.*<.*> (/.*) *?.*$/;
    $PROGNAME = $1;
    print "The program called by cron was $PROGNAME\n";
  }
}

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links