Run shell script on different machine using perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run shell script on different machine using perl script
# 1  
Old 04-27-2012
Run shell script on different machine using perl script

I want to execute my shell script on remote machine using SSH in perl script.
Please help me with syntax.
# 2  
Old 04-28-2012
This is a simple example of copying a file to a remote host via scp:
Code:
# Copy file to remote server
print "**Copying file($file_name) to $host.\n";
$shell_cmd  =  "scp -p ${local_dir}/${file_name} ${user}\@${host}:${dir_for_file}";
$retval     =  system( $shell_cmd );
if ($retval != 0) {
  print "**Error: Could not copy file($local_dir/${file_name}) to $host: ${dir_for_file}.\n";
  return 1;
}
else {
  writelog ("INF Successful copy of file($local_dir/${file_name}) to $host: ${dir_for_file}");
  print "**Successful copy of file($local_dir/${file_name}) to $host: ${dir_for_file}\n";
}




This is a simple example of running script, command, etc. on remote host via ssh:
Code:
# Unzip files from zip file on remote host
print "**Unzipping files from zip file($zip_file_name) on $host to directory(${files_dir_for_rpt_files}).\n";
$shell_cmd  =  "ssh ${user}\@${host} 'unzip -jo /tmp/${zip_file_name} -d ${files_dir_for_rpt_files}'";
$retval     =  system( $shell_cmd );
if ($retval != 0) {

  print "**Error: Error unzipping zip file($zip_file_name) on $host in /tmp to ${files_dir_for_rpt_files}.\n";
  return 1;
}
else{
  print "**Successful unzipping of files from zip file($zip_file_name) on $host to directory(${files_dir_for_rpt_files}).\n";
}

# 3  
Old 04-28-2012
That is 99% shell code with a thin layer of perl, why not just do it in shell?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Perl program to run a Shell script issues...

Hi all, I have the following Perl script which is intended to run a Shell script and generate some logging for the purposes of tracking weather or not the script ran. I get an error, of course, since I don't know what I'm doing really. Here is the code: #!/opt/perl/bin/perl -w ... (14 Replies)
Discussion started by: zixzix01
14 Replies

3. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

4. UNIX for Advanced & Expert Users

Unable to run the script on remote machine Using Expect script

Not able to execute the file in remote host using except utility I am automating the SFTP keys setp process: So i created the expect script for controlling the output of shell below is my main code: Code: #!/usr/bin/expect set fd set password close $fd set df set app close $df... (1 Reply)
Discussion started by: Manoj Bajpai
1 Replies

5. UNIX for Dummies Questions & Answers

how to use ssh to run shell script on a remote machine?

how to use ssh to run shell script on a remote machine? ssh user@remote sh ./script.unx i ran the above command ./script.unx HAS NOHUP COMMAND IN ITS BODY, I AM GETTING ERROR AS NOHUP NOT FOUND... i tried to run that script from remote server, its working fine do ineed to set... (6 Replies)
Discussion started by: only4satish
6 Replies

6. Shell Programming and Scripting

shell script to run after ssh logout from another machine

Scenario: I currently manager a cluster at work which is on a private network and i constantly need to ssh to other clients for diags e.t.c. I created a debain client which i use as my gateway to get to all the clients on the private network and I then created a Shell menu script which will make... (4 Replies)
Discussion started by: defamer
4 Replies

7. Shell Programming and Scripting

How to run perl script in remote machine from java application?

Hi I am working in a java application. I need to execute a perl script(linux) which is in remote machine in java application from local machine(windows). I need to do this process automatically that is without manual intereption. Now I will explain the process clearly, at present to run the... (1 Reply)
Discussion started by: bassma
1 Replies

8. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

9. Shell Programming and Scripting

How to run perl code within a shell script...?

Hi, I have a sheel script that invokes a perl script...Now, instead havin the perl script as a separate file I'd like put the contents in the sheel script itself...But I am not sure how ro run that perl script contents.please help me Thanks (1 Reply)
Discussion started by: vijay_0209
1 Replies

10. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script (auto.pl). I run the perl script using perl auto.pl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script blue.sh has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies
Login or Register to Ask a Question