Jump to content




Recent Status Updates

  • Photo
      16 Sep
    Kadence

    Some spammers sign up to CC and then they leave their account hidden so they think it won't get noticed but with an obvious name like "SaxophoneRetailSingapore" it's hard not to know they are a spam bot. #ModLife

    Show comments (3)
  • Photo
      15 Sep
    Error

    Programming is something that I enjoy and want to make a career out of. But, I usually tend to start things and not finish them. Any advice on how I can finish what I start?

    Show comments (1)
  • Photo
      12 Sep
    FacetiousTurtle33

    Just joined. Really enjoy this sight. Excited to become a great programmer, and helper.

    Show comments (3)
View All Updates

Developed by Kemal Taskin
Photo
- - - - -

Convert perl script to shell script


This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1 milanjain7

milanjain7

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 28 January 2013 - 03:56 AM

can anyone help me to convert below perl script into shell script:

#!/usr/bin/perl
use Env;
$status=$ENV{INSTALLATION} . "/PassPort/bin/executiveStatus";
$startCmd=$ENV{INSTALLATION} . "/PassPort/bin/startPassport";
do{
system("$startCmd");
$output=`$status`;
$output1=`netstat -an |grep 36090`;
#print $output1;
#print $output;
}while($output1 !~ m/listen/i);


Please share any kind of help/information
Best Regards,
Milan Jain

In addition to above post:
this script is use to ping a port number (in infinite loop) to check whether it is lisnening or not.

#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3,358 posts

Posted 28 January 2013 - 02:08 PM

First, just in case, a reminder : Bash shell scripting resources ;)

Second some first draft of the translation.

status=$INSTALLATION + "/PassPort/bin/executiveStatus";
startCmd=$INSTALLATION + "/PassPort/bin/startPassport";
output=""

while [1 -gt 0]

$startCmd
$output=$status
eval "netstat -an |grep 36090"

done

It's a draft, I have no bash on here, do the corrections and it will run

Edited by BlackRabbit, 28 January 2013 - 02:09 PM.


#3 milanjain7

milanjain7

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 05 February 2013 - 01:01 AM

What about this conditional loop. In above perl script, loop will exit once the given port started listening. how can we do it in shell???

 

while($output1 !~ m/listen/i);

 

 

First, just in case, a reminder : Bash shell scripting resources ;)

Second some first draft of the translation.
 

status=$INSTALLATION + "/PassPort/bin/executiveStatus";
startCmd=$INSTALLATION + "/PassPort/bin/startPassport";
output=""

while [1 -gt 0]

$startCmd
$output=$status
eval "netstat -an |grep 36090"

done

It's a draft, I have no bash on here, do the corrections and it will run


#4 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3,358 posts

Posted 05 February 2013 - 11:19 PM

Ok, let's do that line in an if, still I don't remember what does m/ stand for, is it for multiline? if it is the g at the end stands for it.

It will go like this:

if [$output1 | sed -n "/listen/ig"];  then
 your code
fi
if you save the results in a file instead of into $output1 you can pass the file name as second parameter for sed and you will not need the pipeing ;)

#5 milanjain7

milanjain7

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 06 February 2013 - 12:55 AM

Ok, let's do that line in an if, still I don't remember what does m/ stand for, is it for multiline? if it is the g at the end stands for it.

It will go like this:

if [$output1 | sed -n "/listen/ig"];  then
 your code
fi
if you save the results in a file instead of into $output1 you can pass the file name as second parameter for sed and you will not need the pipeing ;)

Thanks for your help.

I will use this code and will get back to you if I faced any issues :-)