LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2013, 12:01 PM   #1
arrals.vl
Member
 
Registered: May 2012
Posts: 40

Rep: Reputation: Disabled
bash to perl


hi,

can somebody help me to convert this bash script in perl?

Code:
#!/bin/bash

ifconfig -a | grep VIP

if [ $? -ne 0 ] ; then
        echo "No VIP on node2, ending here. No script wil be executed."

else
        echo "VIP is on node2, executing the scripts.."

fi
thank you!
 
Old 03-25-2013, 12:57 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,423

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
Sure, right after you show us what you have done and where you are stuck?
 
1 members found this post helpful.
Old 03-25-2013, 01:34 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,316

Rep: Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878
Quote:
Originally Posted by arrals.vl View Post
hi,
can somebody help me to convert this bash script in perl?
Code:
#!/bin/bash
ifconfig -a | grep VIP
if [ $? -ne 0 ] ; then
        echo "No VIP on node2, ending here. No script wil be executed."
else
        echo "VIP is on node2, executing the scripts.."
fi
thank you!
Sounds like this thread:
http://www.linuxquestions.org/questi...pt-4175453078/

...where you also didn't show any effort of your own. We will HELP you, but we're not going to do things FOR YOU. If you want hints, then I suggest you break down the above script into what each line does, then investigate how to perform each step in perl. For example, the Net::Ifconfig module provides a common interface (between Solaris, Linux(es), OSX, Windows, and and FreeBSD), to the ifconfig information. Examples can even be found:
http://search.cpan.org/~tpaba/Net-If...fig/Wrapper.pm
 
Old 03-26-2013, 05:00 AM   #4
arrals.vl
Member
 
Registered: May 2012
Posts: 40

Original Poster
Rep: Reputation: Disabled
Hi,

thank you for your advices.

This is my script:

Code:
#!/usr/bin/perl
# path to ifconfig
$ifconfig=`/sbin/ifconfig`;
if ($ifconfig !~ /VIP/) {
    print "\VIP is not here.\n";
}

else
{
        print "\VIP is here, proceeding..\n"
}
Would you please advise if there is any other case for ifconfig and VIP that i should take in consideration, except checking for VIP as a string?

thank you!
 
Old 03-26-2013, 05:34 AM   #5
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 1,369
Blog Entries: 3

Rep: Reputation: 565Reputation: 565Reputation: 565Reputation: 565Reputation: 565Reputation: 565
Your call to ifconfig is getting all the interfaces on that machine. You may want to narrow it to a single interface, like eth0 by itself.
 
Old 03-26-2013, 09:47 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,316

Rep: Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878Reputation: 3878
Quote:
Originally Posted by arrals.vl View Post
Hi,
thank you for your advices. This is my script:
Code:
#!/usr/bin/perl
# path to ifconfig
$ifconfig=`/sbin/ifconfig`;
if ($ifconfig !~ /VIP/) {
    print "\VIP is not here.\n";
}

else
{
        print "\VIP is here, proceeding..\n"
}
Would you please advise if there is any other case for ifconfig and VIP that i should take in consideration, except checking for VIP as a string?
All you're doing in your bash script is checking for VIP as a string...why would you need to do anything else here??

And I did advise you to use the Net:Ifconfig module. That gives you portability between different unix/linux systems, and will let you query just a specific interface name. Depending on what it returns, you can perform whatever action you want.
 
Old 03-26-2013, 11:55 AM   #7
arrals.vl
Member
 
Registered: May 2012
Posts: 40

Original Poster
Rep: Reputation: Disabled
Hi,

thank you all for your recommendations!

All the best,
Arvin
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 05:11 AM
bash under perl Braynid Programming 8 11-23-2007 04:16 AM
bash perl elvis Linux - General 9 04-22-2005 06:41 AM
Bash or Perl? philipina Linux - General 3 07-27-2004 07:52 AM
perl/bash sk8guitar Programming 5 07-14-2003 02:06 PM


All times are GMT -5. The time now is 06:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration