Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Bash to perl program conversion

  1. #1
    Join Date
    Jul 2010
    Beans
    85

    Bash to perl program conversion

    I have below code, can someone please advise me how i can convert below bash script code in perl.

    Code:
    
    export ORACLE_BASE=/home/oracle1
    
    lsnrctl start lndb1
    sqlplus '/ as sysdba' 
    startup;
    Last edited by learnbash; October 7th, 2013 at 04:16 PM.

  2. #2
    Join Date
    Mar 2010
    Location
    Metro ATL
    Beans
    Hidden!
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: Bash to perl program conversion

    Learn perl, use cpan modules. avoid system and the `cmd` constructs.

    In the old days there was a sh2p program ... can't find it now ... I must be confused. There definitely was/is an a2p tool.

    However, for something so tiny, it would seem that you just need perl and the http://search.cpan.org/~adamk/Proces...lib/Process.pm module.
    I didn't look, but I'd be shocked if there wasn't an Oracle module or 20.

    Using an oracle module will probably let you start and status everything related to oracle ... or you could just query the process table (like the script does already) and use built-in perl regex and split() to find whatever you seek. The regex engine in perl is the best in the world, IHMO.

    Have fun!

    Why switch to perl? If the script works, that change isn't really useful. I say that as a perl guy, but I only use it when a bash script gets over 40-50 lines.

  3. #3
    Join Date
    Jul 2010
    Beans
    85

    Re: Bash to perl program conversion

    sir,

    this is important point to me to learn perl, if you have help me i can start coding it and will understand other things and ask more question here.

  4. #4
    Join Date
    Mar 2010
    Location
    Metro ATL
    Beans
    Hidden!
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: Bash to perl program conversion

    Quote Originally Posted by learnbash View Post
    sir,

    this is important point to me to learn perl, if you have help me i can start coding it and will understand other things and ask more question here.
    What have you tried so far? Asking for help is fine, but you have to make the effort and try some code. Searching on the internet for "perl tutor" will get you started. If you want to learn current perl methods, then there is a free book - "Modern Perl." Google will find it.

    Randall Schwartz has the Learning Perl book and there are PM (Perl Monger/Monk) groups around the world to join.

    So, what have you done already towards your Perl education?
    Posting some code here would also be a big step.

  5. #5
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Bash to perl program conversion

    I have to chime in and say if you are interested in starting to program in perl (based on this and your other recent thread), then you really ought to start at the basics and learn how perl variables, data structures, control structures, etc work before you just start converting scripts. Having the basics down, which will go pretty fast if you have any programming background at all (which it seems you do), and will allow you to understand and write better scripts down the line. Really, you should pick up a copy of "Learning Perl" and work through it. You can probably get through the book in just a couple weeks (depending on your background, effort, and time), and then you'll have a much better background to understand what you'll get from someone just converting this bash script to perl.

    Also, I would agree again with TheFu on the above script - that's not a script that will likely take very much advantage of the power of perl. Well, except for that piped grep | awk command...might be able to make that shorter with a perl regex

  6. #6
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,163
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Bash to perl program conversion

    well, piped grep | awk command is a fail in itself Awk is functionally a superset of grep capability, if you move to awk greps can go away.

    also there is pgrep that cuts removes the need for the whole ps | grep | grep -v
    http://www.lehman.cuny.edu/cgi-bin/man-cgi?pgrep+1
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  7. #7
    Join Date
    Sep 2006
    Beans
    7,025
    Distro
    Lubuntu Development Release

    Re: Bash to perl program conversion

    Quote Originally Posted by Vaphell View Post
    well, piped grep | awk command is a fail in itself Awk is functionally a superset of grep capability, if you move to awk greps can go away.

    also there is pgrep that cuts removes the need for the whole ps | grep | grep -v
    http://www.lehman.cuny.edu/cgi-bin/man-cgi?pgrep+1
    Yes. learnbash, can you explain a little about what you want out of this line?

    DBSTATUS=`ps -ef |grep $PMON_PROC |grep -v grep |awk -F " " '{print $8}'`

    If you walk us through it, it can be shortened down to use just pgrep by itself. After that you can show us how far your perl version has gotten, even if it is not yet perfect.

  8. #8
    Join Date
    Jul 2010
    Beans
    85

    Re: Bash to perl program conversion

    In this variable i am checking oracle database pmon process name. I have Perl v5.14.4

  9. #9
    Join Date
    Sep 2006
    Beans
    7,025
    Distro
    Lubuntu Development Release

    pgrep

    What do you think about using pgrep as suggested above? It could replace several lines if used in the "if" statement. Try it with "-x"

    About converting it to perl for learning purposes, what do you have so far in perl? Maybe you can post it in some etherpad or pastebin style site.

  10. #10
    Join Date
    Jul 2010
    Beans
    85

    Re: pgrep

    Quote Originally Posted by Lars Noodén View Post
    What do you think about using pgrep as suggested above? It could replace several lines if used in the "if" statement. Try it with "-x"

    About converting it to perl for learning purposes, what do you have so far in perl? Maybe you can post it in some etherpad or pastebin style site.
    Right Agree pgrep is also good, i will check that. I tried this.

    Code:
    $ENV{'ORACLE_BASE'} = "/home/oracle1";
    system("lsnrctl start lndb1");
    
    sqlplus as / sysdba, startup ------- > i don't know how to put in perl script.
    Last edited by learnbash; October 8th, 2013 at 04:27 AM.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •