Jump to content




Recent Status Updates

  • Photo
      15 Nov
    duzamucha

    Hi, I am final year Interior Design Student from University of Huddersfield. I am currently working on my final major project which is going to be linked to coding. I was hoping that you could help me with my research. I have prepared a short survey, it would be a massive help if you could fill it in for me. It takes less than 2 minutes to complete, I promise. Here is the link: https://www.surveymonkey.com/s/73XLJKK Thank you so much in advance!

View All Updates

Developed by TechBiz Xccelerator
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,539 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,539 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 :-)






Powered by binpress