简体   繁体   中英

ssh to remote machine via proxy server to run a script with parameters

I want to ssh to a machine via proxy server and run a script on that server with the inputs as parameters passed

I am using below :

ssh -t tooladm@200.81.36.188 "ssh -t tooladm@apuatt01" ". ./.profile >/dev/null 2>&1; cd /astxpinfs/ast/tooladm/JHF_SYNC_Particular_HF ; ./SyncToSite.ksh $product $release "${hf_list}" ${LOG_DIR_NAME} 2>&1 > /dev/null"

For clearance :

Suppose I am in machine A, and want to run the script located in machine apuatt01 There is no direct connectivity b/w machine A and apuatt01 So I am connecting apuatt01 via 200.81.36.188

By using this, I am not able to run the above script

Please can you help, where I am doing wrong

You can use Bash here document to make the script cleaner:

ssh -t tooladm@200.81.36.188 -- ssh -t tooladm@apuatt01 <<EOS
source .profile >/dev/null 2>&1
cd /astxpinfs/ast/tooladm/JHF_SYNC_Particular_HF
./SyncToSite.ksh $product $release "${hf_list}" ${LOG_DIR_NAME} 2>&1 > /dev/null
EOS

Note, the double dash separates the command from arguments passed to ssh .

This syntax works in ksh , too. From the KornShell manual( man ksh ):

<<[-]word The shell input is read up to a line that is the same as word after any quoting has been removed, or to an end-of-file.
No parameter substitution, command substitution, arithmetic substitution or file name generation is performed on word. The resulting document, called a here-document, becomes the standard input. If any character of word is quoted, then no interpretation is placed upon the characters of the document; otherwise, parameter expansion, command substitution, and arithmetic substitution occur, \\new- line is ignored, and \\ must be used to quote the characters \\, $, `. If - is appended to <<, then all leading tabs are stripped from word and from the document. If # is appended to <<, then leading spaces and tabs will be stripped off the first line of the document and up to an equivalent indentation will be stripped from the remaining lines and from word. A tab stop is assumed to occur at every 8 columns for the purposes of determining the indentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM