November 4th, 2012, 11:39 AM
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
November 4th, 2012, 11:42 AM
November 4th, 2012, 11:56 AM
It is just a stupid policy that is in my work place Sir.
November 4th, 2012, 12:04 PM
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).
November 4th, 2012, 12:13 PM
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.
November 4th, 2012, 12:43 PM
Originally Posted by FishMonger
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.
November 4th, 2012, 01:59 PM
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.
November 4th, 2012, 03:54 PM
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.
November 5th, 2012, 12:13 PM
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
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
- the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
BIT COINS ANYONE
November 5th, 2012, 08:22 PM
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:
Originally Posted by Bindo
ssh_results=`ssh user@host '. ./.profile;sqlplus -S user@instance/password <<ENDSQL
set linesize 500 heading off feedback off
select sysdate from dual;
ssh_results=`print $ssh_results | tr -d '\f '`
November 14th, 2012, 06:22 AM
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.
November 14th, 2012, 06:23 AM
Thank you very much Mr SpaceBar. This sounds quite promising.
Originally Posted by spacebar208
November 15th, 2012, 05:58 AM
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.