473,586 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

running shell script from perl script

9 New Member
i have a netwok,and i have a perl script running on a machine(say machine1). the purpose of the script is to login to each of the other machines using ssh. i am able to logon to other machne (say machine2) byusing the following code

system("ssh <host_ip>");

after loging on to the network i need to run another perl script that is saved on the machine2. i want it to be done from the perl script running on machine1. i tried to do it by giving

perl filename.pl > testfile.txt ***(i used the testfile to check wheether it is getting executed)

after loging on to machine2(ssh machine2) from the perl code running on machine1. but it is not working.

is there any way to solve the problem?
Feb 17 '08 #1
6 3213
KevinADC
4,059 Recognized Expert Specialist
look into the Net::SSH module instead of shelling out to ssh. Search CPAN for Net::SSH

search.cpan.org
Feb 17 '08 #2
docdiesel
297 Recognized Expert Contributor
Hi,

try to give the command (or even script) to be executed by stdin:

Expand|Select|Wrap|Line Numbers
  1. system(" echo 'perl filename.pl >testfile.txt'  | ssh rmtserver ");
  2. # or
  3. system(" cat centr_mngd_code.pl   | ssh rmtserver 'perl >testfile.txt' ");
Additionally the second option gives you the possibility to store your perl script once on machine A while being able to execute it on the remote servers.

Another way I often used is the executing "outer scripts" or commands within back ticks:
Expand|Select|Wrap|Line Numbers
  1. $cmd_output = ` some_script.pl ` ;
  2. # or
  3. $cmd_output = ` perl some_script.pl ` ;
Regards,

Bernd
Feb 18 '08 #3
KevinADC
4,059 Recognized Expert Specialist
Hi,

try to give the command (or even script) to be executed by stdin:

Expand|Select|Wrap|Line Numbers
  1. system(" echo 'perl filename.pl >testfile.txt'  | ssh rmtserver ");
  2. # or
  3. system(" cat centr_mngd_code.pl   | ssh rmtserver 'perl >testfile.txt' ");
Regards,

Bernd
You can run scripts on remote machines like that?
Feb 19 '08 #4
docdiesel
297 Recognized Expert Contributor
@KevinADC:

yes, you can. We're using the "cat script | ssh remotesrv" method to use, hm, a remote linux server as "external coprocessor" for our mainframe: The host is sending the shell commands via ssh, the linux system is executing them.

Regards,

Bernd

P.S.: Of course you've got to exchange ssh keys between the systems for remote login without password.
Feb 19 '08 #5
KevinADC
4,059 Recognized Expert Specialist
@KevinADC:

yes, you can. We're using the "cat script | ssh remotesrv" method to use, hm, a remote linux server as "external coprocessor" for our mainframe: The host is sending the shell commands via ssh, the linux system is executing them.

Regards,

Bernd

P.S.: Of course you've got to exchange ssh keys between the systems for remote login without password.
I see, very useful if the OP can shell in like that.

Thanks
Feb 19 '08 #6
rohitbasu77
89 New Member
the main funda is to pass the shell command through ssh....
So, pipe the command through ssh.
then the ssh session will open and the command will pass through it.
it will take the enviroment variable of the remort machine.

for all this you need to creat the genkey. for public and private key in ssh.
so no password is required for the remort machine.

regards
rohit
Feb 21 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
14348
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package because of a binary module which has to be compiled with Visual C 6. My scripts start with a '#!/usr/bin/env python' shebang, as God intended. ...
2
5658
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info into a file with a 'ps' command. My question is "How to explicitly specify a Korn shell to be used by perl?" Eg of my perl code: ## Begin code...
1
4988
by: speedster | last post by:
Hi. I need some help converting some php to perl. $meminfo = shell_exec( "free -o" ); I need to execute "free-o" in shell and get the results. It grabs memory information about a linux webserver. If it is also possible to run a regular expression on this data that would also be great. It then outputs it in a nice format.
10
2552
by: shumaker | last post by:
I don't need a detailed description of a solution(although I wouldn't mind), but I am hoping someone could tell me in general the best path to go about accomplishing a task, since I don't know all the capabilities of what I have available. I can learn the details myself I think. I am trying to set this up to be as simple to use as possible...
0
1417
by: 123jainmin | last post by:
When I ran a perl script named script.pl which have the the follwing line: system("echo hostname = $HOSTNAME > /tmp/myinfo"); I have another shell script script.ksh which simply call script.pl within the script. the permission on script.ksh is: -rwsr-sr-x WHen I ran script.ksh, I got the error message: Insecure dependency in `` while running...
4
3750
by: benwylie | last post by:
I am running IIS 6.0 on Windows 2003. I would like to be able to run a perl script from a web page and include the output. I have tried doing it with an ssi: <form action='docsearch.shtml' method='get'> <!--#exec cgi="/cgi-bin/docsearch.pl--> </form> This correctly ran the script, but it was unable to include the
2
4593
by: jcor | last post by:
Hi, I'm running Ubuntu 7.04. I Have a perl script. I want it to be running all the time. The way it is working, I must start my script, so when someone turns off the computer it doesn't run anymore. I'd like it to start running when the computer boots. I read something about it in the web and I tried to add the script to /etc/init.d but didn't...
1
2036
by: looza | last post by:
Hi All, I have a bunch of shell script files that use a common shell script file that contains certain global variables that are declared and initialized or derived by some arithmatic. I have to now convert one of the shell script file to a perl file so I can use the in-built functions. Is the a way I can import the file with the globals...
7
6220
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.