lubox.com Posted June 5, 2004 Posted June 5, 2004 Hello, I never ever programmed in perl before but for the last few days, I have been trying to create a small script to check if an app is ruuning and if it's not to run it. And I will call this script in a cron every 5mins. >#!/usr/bin/perl $cmd="ps -A | grep xmms | grep -v grep"; $output=qx/$cmd/; if ($output!=~m/$xmms/) { qx/xmms/; } The problem seem to come from the beginning, as if it was not understanding my first command: ps -A | grep xmms | grep -v grep I asked on a programming ofurm, but noone answered me :/ perhaps I will be more lucky here Ludo Quote
borfast Posted June 5, 2004 Posted June 5, 2004 I have no idea about what could be wrong, as I know nothing about PERL. But I do have one question: why the "grep -v grep" command at the end? Won't the output of the script be just the same without it? Quote
lubox.com Posted June 5, 2004 Author Posted June 5, 2004 Good question Raul In fact I created this script in using several scripts find on Google... I just tried to take off this last part and you are right... it changes nothing! but even without it, it's not working. One small mistake at the time, I'm sure I will get this damned script working! lol Ludo Quote
dmohs Posted June 5, 2004 Posted June 5, 2004 The following line is suspicious: >if ($output!=~m/$xmms/) Is it your intention to have this if statement be true if "xmms" is not found in the output? If so, it would need to be: >if ($output !~ m/xmms/) The proper syntax for "match if not" is "!~". In the above, $xmms will match the variable $xmms which is not defined as you have presented your script. Quote
TCH-Bruce Posted June 5, 2004 Posted June 5, 2004 (edited) Hi Ludo, I'm curious as to why you want to write it in Perl? Couldn't you just do it with a shell script? I'm assuming you are wanting to run this on your own machine, right? Something like this: CMD=`ps -A | grep xmms` if [ ${CMD} = "" ] then execute the command fi Edited June 5, 2004 by TCH-Bruce Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.