LinuxQuestions.org
Help answer threads with 0 replies.
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 12-20-2011, 07:00 AM   #1
sinaigross
LQ Newbie
 
Registered: Dec 2011
Posts: 7

Rep: Reputation: Disabled
using ssh in a script


hi,
i'm writing a script (script 1)which runs on linux machine, that needs to execute a different script (script 2) on a solaris machine. i want to avoid forcing the user to give paasword for the login to solaris plus i need the solaris environment to recognize my variables and therefor i attempt to use:

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${solarisMachine} "cd ${workDir}; ${script2} -list ${file1} -path ${pathFile}".

with this method the script does not run properly (though the login succeeds), however if i login and execute in three different steps it works (as seen below):
1. ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${solarisMachine}
2. cd ${workDir}
3. ${script2} -list ${file1} -path ${pathFile}

any ideas what may cause the difference?

Last edited by sinaigross; 12-20-2011 at 08:15 AM.
 
Old 12-20-2011, 09:14 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,580
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
Use single quotes (') rather than double quotes (").

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${solarisMachine} 'cd ${workDir}; ${script2} -list ${file1} -path ${pathFile}'
 
Old 12-20-2011, 09:35 AM   #3
sinaigross
LQ Newbie
 
Registered: Dec 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks, but tried already

a. the problem remains the same
b. using single quotes takes away the ability to pass variables
 
Old 12-20-2011, 09:58 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Why not use a variable for command, like
Code:
command="cd $workDir; $script2 -list $file1 -path $pathFile"

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${solarisMachine} ${command}
 
Old 12-20-2011, 10:04 AM   #5
sinaigross
LQ Newbie
 
Registered: Dec 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
thanks. tried already :-)

and does not work.
 
Old 12-20-2011, 10:08 AM   #6
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Where $workDir, $script2, $file1, $pathFile are defined ?

In linux script or in solaris shell env ?
 
Old 12-20-2011, 10:12 AM   #7
sinaigross
LQ Newbie
 
Registered: Dec 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
in the linux script

but its not a matter of the variables, it doesn't work hard-coded eather.
 
Old 12-20-2011, 10:19 AM   #8
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Strange, do you provide the full path in $script2 ?
 
Old 12-20-2011, 10:49 AM   #9
sinaigross
LQ Newbie
 
Registered: Dec 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
i can't, sorry, company confidentiality:-)

why does it matter though?
 
Old 12-20-2011, 12:05 PM   #10
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Maybe check if PATH value is the same when you login with ssh, and when you send command directly with ssh

ssh <server> "echo $PATH"

ssh <server>
echo $PATH
 
Old 12-21-2011, 03:16 AM   #11
sinaigross
LQ Newbie
 
Registered: Dec 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
checked, PATH is the same

the script which is used in the ssh (script 2) is a perl script.
the output while running it in the ssh gives "killed" messages, and the script does use perl "system" commands, so my guess is that the call within
the ssh affects system calls somehow. to be more specific, the log file tells that some files failed to be created and that affects the rest.
 
Old 12-21-2011, 07:59 AM   #12
sinaigross
LQ Newbie
 
Registered: Dec 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
problem solved

.cshrc file is not loaded while executing the command in ssh.
changed the command into "source .cshrc; cd ${workDir}; ${script2} -list ${file1} -path ${pathFile}".
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ssh-executed script does not terminate when ssh session killed matthewg42 Linux - General 6 03-24-2011 01:15 PM
[SOLVED] Script question: Shell script in kde to log in on a server with ssh c4719929 Programming 18 01-31-2011 10:26 AM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 04:05 AM
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 03:41 AM
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 05:50 PM


All times are GMT -5. The time now is 11:00 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration