Jump to content




Recent Status Updates

  • Photo
      30 Sep
    rhossis

    laptop hard disk seated beneath motherboard but with no access panel. 7 hours to replace :(

    Show comments (3)
  • Photo
      19 Sep
    Chall

    I love it when you go to write a help thread, then while writing, you reach an enlightenment, and figure it out yourself.

    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,451 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,451 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 :-)