The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Perl remote commands
Discuss Perl remote commands in the Perl Programming forum on Dev Shed. Perl remote commands Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 4th, 2012, 11:39 AM
|
|
Contributing User
|
|
Join Date: Oct 2011
Posts: 48
Time spent in forums: 10 h 41 m 26 sec
Reputation Power: 2
|
|
|
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 
|

November 4th, 2012, 11:42 AM
|
|
|
Quote: | --no CPAN modules are allowed to install. |
Why not?
|

November 4th, 2012, 11:56 AM
|
|
Contributing User
|
|
Join Date: Oct 2011
Posts: 48
Time spent in forums: 10 h 41 m 26 sec
Reputation Power: 2
|
|
|
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
|
|
Contributing User
|
|
Join Date: Oct 2011
Posts: 48
Time spent in forums: 10 h 41 m 26 sec
Reputation Power: 2
|
|
Quote: | 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.
|

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
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 65
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
|
|
|
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
|

November 5th, 2012, 12:13 PM
|
 |
'fie' on me, allege-dly
|
|
Join Date: Mar 2003
Location: in da kitchen ...
|
|
|
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
Deta vil - 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
|
 |
Contributing User
|
|
Join Date: Apr 2012
Location: spaceBAR Central
|
|
Quote: | 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
|

November 14th, 2012, 06:22 AM
|
|
Contributing User
|
|
Join Date: Oct 2011
Posts: 48
Time spent in forums: 10 h 41 m 26 sec
Reputation Power: 2
|
|
|
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
|
|
Contributing User
|
|
Join Date: Oct 2011
Posts: 48
Time spent in forums: 10 h 41 m 26 sec
Reputation Power: 2
|
|
Thank you very much Mr SpaceBar. This sounds quite promising.
Quote: | 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
|
|

November 15th, 2012, 05:58 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 5 m 43 sec
Reputation 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|