LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-21-2013, 04:03 PM   #1
sanaz
Member
 
Registered: Aug 2012
Posts: 76

Rep: Reputation: Disabled
Running script remotely


I'm trying to remotely run a script and I'm using the following command:
Code:
ssh root@192.168.122.193 /home/guest/Desktop/measure.sh
when I execute the command , it asks me password and wait for almost 10 seconds(usually it takes 10 secs to run measure.sh). measure.sh is supposed to also redirect result of script to a file, when normally I run script on the machine its located, I can see the output file, but when I run it remotely, the output file is not created. I do not know what is the problem and any help is appreciated.
 
Old 02-21-2013, 04:22 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
There could be several reasons .. try adding 'set -x' to the top of your script (after the shebang(#!) though)
 
Old 02-21-2013, 04:37 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
1. It asks for root password for the machine where you're trying to login.

2. It either takes time in establishing connection, or there's some issue with shell on remote machine. May be a different shell configured for root on remote machine as compare to your local machine. So once invoke:
Code:
~$ ssh root@192.168.122.193 "echo $SHELL"
Also check if /home/guest/Desktop/measure.sh exists on remote machine or not? I doubt it's on your local machine, and you're trying to run it on remote machine.

3. If output file isn't generated then I doubt that your script is running on remote server or may be it doesn't exist on remote machine. So once login on remote machine and invoke it (not with ssh) like:
Code:
~$ ssh root@192.168.122.193
~$ /home/guest/Desktop/measure.sh
Let's know the results.
 
Old 02-21-2013, 06:46 PM   #4
sanaz
Member
 
Registered: Aug 2012
Posts: 76

Original Poster
Rep: Reputation: Disabled
I am sure that the file exists and it is running correctly. I've added set -x to the beginning of file and when running it remotely I got this:
Code:
root@192.168.122.193's password: 
++ count=0
++ LOG=./measure_download_speed.log
++ exec
++ exec
But again the log file(which should be measure_download.log) is not created. In fact the script is downloading a file from server and measure the time. Even the file which should be downloaded does not exist.

What I noticed is the following:
the downloaded files and log are created in the root directory (/root/)of remote machine. But I need them to be in the Desktop, I know that I can write script to move them to Desktop, but I have more than 100 experiments and I should to that for all of them. I just want to fix this problem.




And
Code:
# ssh root@192.168.122.193 "echo $SHELL"
root@192.168.122.193's password: 
/bin/bash
And
running
Code:
~$ ssh root@192.168.122.193
~$ /home/guest/Desktop/measure.sh
also does not work, but if after ssh I enter the directory containing script and run it it works. I guess the problem is I can run it outside its directory.

Last edited by sanaz; 02-21-2013 at 06:59 PM.
 
Old 02-21-2013, 06:53 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Most likely the log has been created in the HOME directory of the remote machine (and maybe even the file was downloaded there). You have to options: use absolute paths inside the script or change to the directory containing the script itself. You can do this from inside the script in a reliable way using:
Code:
cd "$(dirname "$(readlink -f "$0")")"
 
Old 02-21-2013, 08:41 PM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Alright. I guess that problem is with difference in shebang (script interpreter) and login shell.
If both are not same, then you will need to run script with shell name.

So check if shebang (script interpreter) is also #!/bin/bash. And in that case, you can invoke script like:
Code:
~$ /home/guest/Desktop/measure.sh
Else, you would need to invoke it as (depends upon shebang):
Code:
~$ sh /home/guest/Desktop/measure.sh
 
Old 02-21-2013, 10:30 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
The default dir is the one you login to, so $HOME, even though you call it in /home/guest/Desktop.
Easiest fix is to cd /home/guest/Desktop at the top of the script, before it does any processing.
Alternately, tell the process (downloader?) where to put files/logs.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running multiple commands remotely via SSH in a script gimpy530 Linux - General 4 12-19-2009 10:22 PM
Running X Application remotely arivupp Linux - General 3 05-08-2009 07:25 AM
keep running x programs remotely kichukov Linux - Software 16 10-23-2005 11:52 AM
Running a shell script remotely via 'ssh <hostname> <command>' davee Linux - General 4 10-09-2005 01:38 AM
Running X-WINDOW remotely consistgd Linux - Software 8 11-12-2004 04:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration