Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Capture output of remote script execution

Posted on 2009-07-08
3
Medium Priority
?
1,301 Views
Last Modified: 2013-12-16
Hi

I do the following things on a remote linux box from a local linux box.

1. SCP a bash script to the remote system
2. SSH to the remote system and execute the bash script you copied in step 1.
3. Display the output of the remote script execution in the local machine.

I'm facing trouble with step 3. I could able to remotely execute the script. I verified this. But the script execution is not redirected to the local machine from where i'm executing.

What i have to do in my base script..?

#!/bin/sh
#Master script I execute on the local machine
scp test.sh 192.168.1.10:/var/local
ssh 192.168.1.10 "sh /var/local/test/sh
 
#!/bin/sh
#Remote script
mkdir /var/local/testdir
echo "Created test directory"

Open in new window

0
Comment
Question by:shanraj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 150 total points
ID: 24804131
try

ssh 192.168.1.10 "sh -x /var/local/test/sh" > localfile
0
 

Expert Comment

by:notmistaken
ID: 24805467
One tool I use a lot to capture output from scripts is Expect. You can run your script on the remote host using Expect which will capture all the output, then you need to find a way to get the results back to your local host. This could be done by writing the output to a directory which is mounted on your local host from the remote host. Your local script could search the mounted directory until you see the file which contains the output.

Expect is an Open Source tool based on the language Tcl. You can find details on http://expect.nist.gov/
0
 

Author Closing Comment

by:shanraj
ID: 31601476
As Omarfarid said I routed the output to a local file and displayed the content of the file.

I also found another way. If you have arguments @$ in the main section of the script it displays the output without anything special. that's cool..

thanks for all.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question