Reputation: 1218
I'm trying to run a command inside Scala, this command is a ssh call that require the execution of a cmd line inside the serve machine, it looks like
sshpass -p PSW ssh USER@IP "/absolute_path/program -input /absolute_path/filename"
if I print this string from Scala and run it directly inside the shell it works correctly, but running it using
cmd !
the SERVER returns an error
bash: /absolute_path/program -input /absolute_path/filename: No such file or directory
someone can tell me how fix please? thank you
UPDATED
var nestedcmd = "/absolute_path/program" +
" -input "+ server_dir +"/"+ filename
var cmd = "sshpass -p "+ server_pass +
" ssh "+ server_user +"@"+ server_ip +
" \""+ nestedcmd + "\""
println(cmd)
cmd !
println produces the query that I'm trying to run directly inside the shell, cmd ! should run the same command
I'm using this solution during the development, because in production the code will be run directly into the server and I will not need ssh call, but for development I need to run the "program" on the server from my pc
SOLVED
It was sufficient remove the quotes, ssh takes what comes after the connection parameters as commands to run on the server
Upvotes: 0
Views: 476
Reputation: 6871
Using formatted strings can help with such problems
var nestedcmd = """/absolute_path/program -input $server_dir/filename"""
var cmd = """sshpass -p $server_pass ssh $server_user@$server_ip \$nestedcmd"""
Upvotes: 0