Jump to content

Recommended Posts

Posted

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

Posted

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?

Posted

Good question Raul :dance:

 

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

Posted

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.

Posted (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 by TCH-Bruce

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...