简体   繁体   中英

how to do ssh from the bash script

I have tried to run the following command from command line and it works perfect as expected

ssh someIP "java -jar /path/program.jar "someIP""

but when i wrote in the bash script as following:

 ssh $f1 \"java -jar /path/program.jar   \"$f1\"\" ;

where $f1 is the ip address. it does not work and gives me the error:

bash: java -jar /path/program.jar someIP: No such file or directory

I tried to echo the ssh command and it is correct and i just copied the echoed command and pasted on the command prompt and it has worked. So I am now confuse, what is wrong in the bash script that I am missing

You can try not to escape.

#!/bin/bash
ssh $1 "java -jar program.jar "$1""

You could try EOF.

ssh $1 << EOF
            #commands here
EOF

After the commands are done the connection is severed.

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