[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

Convert this Windows script to a perl script so I can use it on Macbook

Hey there... I have a script that I used in cygwin:

#!/bin/bash
 
GM=$1
 
 
if [ "$1" == "-h" -o "$1" == "--help" -o "$#" -ne 1 ] ; then
  echo "$0 <GM_IPaddr> "
  echo " Provide the IP address of the Grid Master as the one argument to this command"
  exit 1
fi
 
 
wget --no-check-certificate https://${GM}/api/dist/CPA<wbr ></wbr>N/authors/<wbr ></wbr>id/SHARK
 
PerlPkg=`cat SHARK| grep "tar.gz" | awk -F'"' '{print $2}'`
PDIR=`echo $PerlPkg | sed 's/.tar.gz//'`
 
wget --no-check-certificate https://${GM}/api/dist/CPA<wbr ></wbr>N/authors/<wbr ></wbr>id/SHARK/$<wbr ></wbr>{PerlPkg}
 
tar xzvf $PerlPkg
 
mv $PerlPkg $PDIR
 
rm -f SHARK
 
cd $PDIR
   pwd
   /usr/bin/perl ./Makefile.PL
   /usr/bin/make
   /usr/bin/make test
   /usr/bin/make install
cd ..
 
##### End Script #####

Open in new window


I need to somehow convert it to perl script that I can run on my macbook

Thanks!
0
richsark
Asked:
richsark
  • 6
  • 2
  • 2
  • +1
1 Solution
 
farzanjCommented:
This is not a windows script.  I know you ran it on Windows but it is Bash so you should be able to run it on Mac without a problem.

On the shell, try command:

which bash

If you see response, all you need to do is to adjust paths accordingly
0
 
richsarkAuthor Commented:
I did that but it does not run as is.

I think I may need to replace the line:

from
wget --no-check-certificate https://${GM}/api/dist/CPAN/authors/id/SHARK

to:
curl --insecure https://${GM}/api/dist/CPAN/authors/id/SHARK

Is there a way not to use bash and use perl. so all I need to do is run it as:

./upgrade-API.pl
0
 
richsarkAuthor Commented:
This is what I get:

richards-macbook-air|richsark_air$ ./update-api.sh 192.168.0.222

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://192.168.0.222/api/dist/CPAN/authors/id/SHARK/">here</a>.</p>
</body></html>
cat: SHARK: No such file or directory
tar: Option f requires an argument
Usage:
  List:    tar -tf <archive-filename>
  Extract: tar -xf <archive-filename>
  Create:  tar -cf <archive-filename> [filenames...]
  Help:    tar --help
usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory
/Users/richsark_air
Can't open perl script "./Makefile.PL": No such file or directory
make: *** No targets specified and no makefile found.  Stop.
make: *** No rule to make target `test'.  Stop.
make: *** No rule to make target `install'.  Stop.

richards-macbook-air|richsark_air$
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
arober11Commented:
Hi

Mac OS X comes bundled with purer / older BSD Unix variants of the commands in your script, but you can easily install the GNU variants of wget or [g]awk, found in cygwin, via either: Homebrew, MacPorts or  Fink.
0
 
richsarkAuthor Commented:
I tried macports but it hangs on installing.
richsark
Aug 28, 2012 12:02 AM
I have a new 2012 2 gen MBA. 256 SSD 8GB i7
 
Trying to install
 
port -d install gmake
 
Its been hanging on this section for 4 hours now...
 
checking how to run the C preprocessor... /usr/bin/clang -E
checking for grep that handles long lines and -e... (cached) /usr/bin/grep
checking for egrep... /usr/bin/grep -E
 

There is an issue I think for mountain lion from what I seen.

As a work around can this one I have be reformatted to run on my Mac please.
0
 
arober11Commented:
Personally i'd perseveer with getting a local variant of wget, e.g. via homebrew e.g.

ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
...

brew install wget

Open in new window


but if you want to go down the curl route you'll need to tell curl to follow the 301 redirect (which it won't do by default, unlike wget) e.g.

curl -kLOs https://${GM}/api/dist/CPAN/authors/id/SHARK

Open in new window

0
 
richsarkAuthor Commented:
ok, can we take it from the top as its may be easier for me and anyone else who wants to help :)

I like to run this script as update-api.pl 100.100.100.1 (( the IP adress of where its at. it could be different other time ))

what I need for it to do it like so:

1st:
if [ "$1" == "-h" -o "$1" == "--help" -o "$#" -ne 1 ] ; then
echo "$0 <GM_IPaddr> "
echo " Provide the IP address of the Grid Master as the one argument to this command"
exit 1
fi

Then:

Look the for tar.gz it downloaded "shark.ar.gz"

unpack it

then run these

cd $PDIR
   pwd
   /usr/bin/perl /Makefile.PL
   /usr/bin/make
   /usr/bin/make test
   /usr/bin/make install
cd ..


no-check-certificate https://${GM}/api/dist/CPAN/authors/id/SHARK
0
 
FishMongerCommented:
It's not clear to me if you already know the full path of the file you need to download, or if you first need to parse an html page to get the path.

Is it necessary for you to use --no-check-certificate?  If not, then I'd use the LWP::Simple module to retrieve the file instead of wget.  If you do need that option, then I'd switch to LWP::Curl which supports that option and follows redirects.
0
 
richsarkAuthor Commented:
Hi Fishmonger.. so assume I get LWP for my mac. What changes below do you think I need to make?

#!/bin/bash
 
GM=$1
 
 
if [ "$1" == "-h" -o "$1" == "--help" -o "$#" -ne 1 ] ; then
  echo "$0 <GM_IPaddr> "
  echo " Provide the IP address of the Grid Master as the one argument to this command"
  exit 1
fi
 
 
wget --no-check-certificate https://${GM}/api/dist/CPA<wbr ></wbr>N/authors/<wbr ></wbr>id/SHARK
 
PerlPkg=`cat SHARK| grep "tar.gz" | awk -F'"' '{print $2}'`
PDIR=`echo $PerlPkg | sed 's/.tar.gz//'`
 
wget --no-check-certificate https://${GM}/api/dist/CPA<wbr ></wbr>N/authors/<wbr ></wbr>id/SHARK/$<wbr ></wbr>{PerlPkg}
 
tar xzvf $PerlPkg
 
mv $PerlPkg $PDIR
 
rm -f SHARK
 
cd $PDIR
   pwd
   /usr/bin/perl ./Makefile.PL
   /usr/bin/make
   /usr/bin/make test
   /usr/bin/make install
cd ..
 
##### End Script #####
                                  

Open in new window

0
 
FishMongerCommented:
I'm not sure how to answer that question since I work with Perl scripts, not bash scripts and you haven't provided any info on the problems that you're experiencing in converting this bash script to a Perl script.
0
 
richsarkAuthor Commented:
Thread closed
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now