#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    42
    Rep Power
    3

    Perl remote commands


    Greetings Mr Fish/Laurent and All other good gentlemen

    Im trying to write a script where I need to run some commands on a remote server. Following is the description
    --script is being run from the host A
    --no CPAN modules are allowed to install.

    1. ssh in to the host B which is an oracle box (public key ssh is enabled & )
    2. from host B, I need to be able to connect to the DB as sysadmin (sqlplus "/ as sysdba") and run a command probably ("select * from tab;") and assign it in to a variable.

    Could someone please help me? I'd really appreciate it.

    Many thanks in advance
    /Bindo
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    --no CPAN modules are allowed to install.
    Why not?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    42
    Rep Power
    3
    It is just a stupid policy that is in my work place Sir.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    830
    Rep Power
    496
    If you can't use CPAN modules, you will probably need to issue a series of Unix commands to the system, using the system command or the backticks.

    I haven't tried it, but I think it should work (I have done relatively similar things in shell scripts, but quite some time ago, I don't remember the details).
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    Then your employer doesn't have a clue about perl.

    Can this task be done in Perl without the use of any modules? Yes it can.

    Should it be written without the aide of modules? Absolutely not.

    Without the use of modules, your script will boil down to a collection of system calls and with that in mind, you should write a shell script.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    42
    Rep Power
    3
    Originally Posted by FishMonger
    Then your employer doesn't have a clue about perl.

    Can this task be done in Perl without the use of any modules? Yes it can.

    Should it be written without the aide of modules? Absolutely not.

    Without the use of modules, your script will boil down to a collection of system calls and with that in mind, you should write a shell script.

    Thanks Mr Laurent. i tried the system command but I could only get to the host B via ssh. I have no clue as to how I should run sqlplus henceforth.

    Thanks Mr Fish. I totally agree with you about the CPANs. I'll try a little more and see if I get lucky sir. Thanks anyways.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    830
    Rep Power
    496
    It really depends on the system and set-up on platform B. You may need to source the .profile (or something equivalent) before you can run the sqlplus command, so that the environment variables are correctly set-up.

    It usually takes a bit of trying various things before succeeding to have it right.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    82
    Rep Power
    3
    Hi Bindo,
    I had the same problem at my work - nothing can be installed (including Perl modules) on any of the machines but then I learn how do do this manually (thanks to this website, Fish and Omega personally). Try it Dude, your life will become much easier.
    Thanks, testerV
  16. #9
  17. 'fie' on me, allege-dly
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,889
    Rep Power
    6444
    First off, I'd prefer not advising people to violate their workplace policies, as it could result in disciplinary procedures being levied against them, or worse, dismissal

    Sometimes it helps to think of policies as living documents which can be changed over time, with some controlling restraints, like logs of permitted policy breach, with management signoff, etc, etc

    banking and other organisationsare completely anal about some of these policies and it's with good reason, as undocumented software changes in production environments are not something to be taken lightly

    If they are rigid on this policy, then ask about their software release methodology/policy

    HTH
    --Ax
    without exception, there is no rule ...
    Handmade Irish Jewellery
    Targeted Advertising Cookie Optout (TACO) extension for Firefox
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


    09 F9 11 02
    9D 74 E3 5B
    D8 41 56 C5
    63 56 88 C0
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
    -- Jamie Zawinski
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE
  18. #10
  19. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    Originally Posted by Bindo
    1. ssh in to the host B which is an oracle box (public key ssh is enabled & )
    2. from host B, I need to be able to connect to the DB as sysadmin (sqlplus "/ as sysdba") and run a command probably ("select * from tab;") and assign it in to a variable.
    This is a simple example of using ssh to run sqlplus on remote host and populate variable on local host which is what I believe you are trying to do:
    Code:
    #!/bin/ksh
    # test_ssh.sh
    ssh_results=`ssh user@host '. ./.profile;sqlplus -S user@instance/password <<ENDSQL
    set linesize 500 heading off feedback off
    select sysdate from dual;
    ENDSQL'`
    ssh_results=`print $ssh_results | tr -d '\f '`
    print "$ssh_results"
    
    $ test_ssh.sh
    05-NOV-12
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    42
    Rep Power
    3
    Im extremely sorry for late response.

    Thank you very much all for good advices. I will get back to you soon once I try to put up something with your guidance. Thanks again good gentlemen.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    42
    Rep Power
    3
    Thank you very much Mr SpaceBar. This sounds quite promising.





    Originally Posted by spacebar208
    This is a simple example of using ssh to run sqlplus on remote host and populate variable on local host which is what I believe you are trying to do:
    Code:
    #!/bin/ksh
    # test_ssh.sh
    ssh_results=`ssh user@host '. ./.profile;sqlplus -S user@instance/password <<ENDSQL
    set linesize 500 heading off feedback off
    select sysdate from dual;
    ENDSQL'`
    ssh_results=`print $ssh_results | tr -d '\f '`
    print "$ssh_results"
    
    $ test_ssh.sh
    05-NOV-12
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Depending on how your environment is set up, you can create processes on remote machines using WMI. Consult with your network / Windows administrator for the proper approach.

    Short of finding out what mechanisms are available on Windows, we can't help you. This is not as much a Perl question but a question about your computing environment, and you are much closer to the people who know about that than we are.

IMN logo majestic logo threadwatch logo seochat tools logo