Convert .sh script into perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert .sh script into perl
# 1  
Old 10-15-2009
Convert .sh script into perl

Good afternoon to you all

I really need your help


I have the following script developed in .sh and I need to convert it into perl. Can someone help me do it please?

Here´s the script:
Code:
##############################################

##############################################

cat /var/www/monitor/scripts/TestProbes/probelist.txt | while read probe

        do

{
perl /var/www/monitor/scripts/slabb/getQosData.pl -s DNS -m Availability -c $probe
} >> /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt


                      if [[ -s /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt ]] ; then

 echo "Probe has data"

                      else

echo "Probe has no data" 


                    fi

        rm /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt
        touch /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt
        chmod 777 /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt


        done



############################################


Last edited by pludi; 10-15-2009 at 02:53 PM.. Reason: code tags, please...
# 2  
Old 10-15-2009
Quote:
Originally Posted by zarahel
Good afternoon to you all

I really need your help


I have the following script developed in .sh and I need to convert it into perl. Can someone help me do it please?

Here´s the script:
Code:
##############################################

##############################################

cat /var/www/monitor/scripts/TestProbes/probelist.txt | while read probe

        do

{
perl /var/www/monitor/scripts/slabb/getQosData.pl -s DNS -m Availability -c $probe
} >> /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt


                      if [[ -s /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt ]] ; then

 echo "Probe has data"

                      else

echo "Probe has no data" 


                    fi

        rm /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt
        touch /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt
        chmod 777 /var/www/monitor/scripts/TestProbes/Probes/"$probe".txt


        done



############################################

Why?

All you are doing is running basic commands - half of which I can't understand what or why.

What will perl give you here?
# 3  
Old 10-16-2009
I need to integrate it on an application that only interprets perl.

The script is very simple as you said. It´s only a condition checking if a specific file is empty or not. I just want to convert it into perl.

---------- Post updated 10-16-09 at 11:15 AM ---------- Previous update was 10-15-09 at 04:02 PM ----------

Anyone?
# 4  
Old 10-16-2009
Few thing that you can start with to convert this into perl -

1) File opening /Reading from file/Writing to a file/Executing a script
2) Condition checking (file exist ?)

You can open the file for reading in perl using
open(FHI,"</var/www/monitor/scripts/TestProbes/probelist.txt");

You can read data from this file (alternate of while read line in unix)
while(defined(<FH>))
{

}

How you will execute the perl script in side it ?
system(/var/www/monitor/scripts/slabb/getQosData.pl -s DNS -m Availability -c $probe);

How you will write the contents to a file $probe.txt ??
open(FHO,">/var/www/monitor/scripts/TestProbes/Probes/$probe.'.txt'");

You can check the file exist or not using

if (- e $probe)
{
print "Probe exist\n";
}
else
{
print "Probe missing \n";
}

---Just assemble this idea into your perl script --

Last edited by jambesh; 10-16-2009 at 03:19 PM.. Reason: spell check
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can someone convert this python script to perl

There is a python script that I would like converted to a perl script. If someone has the time to convert the script I would appreciate it. You can find the script below: reboot-mb8600/reboot-mb8600.py at master . j4m3z0r/reboot-mb8600 . GitHub #!/usr/bin/python ''' A hacky script to... (1 Reply)
Discussion started by: azdps
1 Replies

2. Shell Programming and Scripting

Perl Script remove digits and convert

Hello Guy's Quick question which im sure many can answer in seconds. Basically I have a perl script which is running commands to an element and then taking some of the the output and printing it to the screen. One of the outputs is a variable Hex Number. What I would like to do is strip... (1 Reply)
Discussion started by: mutley2202
1 Replies

3. Shell Programming and Scripting

Convert binary to text Perl script

Hello everyone, I have a binary file with a structure unknown. I have found 2 perl scripts that it seems to do the convertion but I get sintactic errors when I run them, may somebody test these 2 scripts please and see if really work? One if from here... (10 Replies)
Discussion started by: Ophiuchus
10 Replies

4. Shell Programming and Scripting

Convert shell script to Perl

Hello,,I have a very small script that contains these lines; and it works perfectly; however I need to use Perl now as I will need to feel variables from a MySQL table into this; to it would be nice to start by converting this first... find / -perm 777 \( -type f -o -type d \) -exec ls -lid {}... (1 Reply)
Discussion started by: gvolpini
1 Replies

5. Shell Programming and Scripting

Help with convert awk script into perl

Input file (a list of input file name with *.txt extension): campus.com_icmp_ping_alive.txt data_local_cd_httpd.txt data_local_cd.txt new_local_cd_mysql.txt new_local_cd_nagios_content.txt Desired output file: data local_cd_httpd data local_cd new local_cd_mysql new ... (9 Replies)
Discussion started by: perl_beginner
9 Replies

6. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

7. Shell Programming and Scripting

convert perl code to shell script

This is about how to Monitoring folder for new files using shell script im doing a project using smsserver tools 3. i have used a perl script to handle incoming messages. the content of each message must be directed to a java program. this program generates the answer to reply to the user... (2 Replies)
Discussion started by: x34
2 Replies

8. Shell Programming and Scripting

Need to convert ksh script to Perl

Guys I am new to this forum, this may seem like a cheeky request. I have been asked by my manager to convert this ksh script to Perl. I do not have the foggiest about Perl and would appreciate any help on this. Basically this scipt automates a recovery process for EMC Legato Networker. It will... (1 Reply)
Discussion started by: rahimm1
1 Replies

9. Shell Programming and Scripting

convert the below perl sript to shell script

perl script: my $logdir = '/smp/dyn/logfiles/fsm/mp/mp'; $logdir = $logdir ."/mp${toDate}*"; i tried to make it..as below .. but not working .. date +%m%d%y logdir = /smp/dyn/logfiles/fsm/mp/mp logdir=$logdir/mp"$date" but it was not working..... can someone please help me out in... (1 Reply)
Discussion started by: mail2sant
1 Replies

10. Shell Programming and Scripting

convert unix script to perl

Hi, I have these lines in a unix script: FILEONE = /<filepath1>/<filename1.txt> FILENEW = /<filepath2>/<filename2.txt> head -5 $FILEONE | sed '1d' > $FILENEW PARAM1 = `cat $FILENEW | awk '{print $2;}' ` echo "Param1 Value: $PARAM1" What's the correct syntax of the above lines if same... (2 Replies)
Discussion started by: gholdbhurg
2 Replies
Login or Register to Ask a Question