473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

running shell script from perl script

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 3200
KevinADC
4,059 Expert 2GB
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 Expert 100+
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 Expert 2GB
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 Expert 100+
@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 Expert 2GB
@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
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
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...
2
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...
1
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...
10
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...
0
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...
4
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'...
2
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...
1
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...
7
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.