Hoi everybody,
I am currently having a problem with sending commands over SSH via command line to a server. To have an easy example, I always send the "pwd" command - which should return the current folder you are in.
I build the initial SSH connection successfully with the following command:
sshg3 user@server#port 'pwd'
which connects to the server and short the home folder.
Afterwards, I use sudo su - user2 - because the user has more rights as user (needed for specific tasks):
sshg3 user@server#port "echo pwd|sudo su - user2"
Here, however, if I want to concat multiple commands after one another, I need to insert "" - otherwise it does not work:
sshg3 user@server#port "echo ""pwd;pwd""|sudo su - user2"
If I have no or only one ", the result is:
pwd
-bash: line 1: {homefolder}: is a directory
Now, afterwards using lftp I need to upload data to that server using yet another user. Using another pipe, I get that to work with a single command the following way:
sshg3 user@server#port "echo ""echo pwd|lftp -u user3 -p 1234 server2""|sudo su - user2"
And now comes the problem: Sending multiple commands to the second server does not work. If I use the same pattern I used before (""), I get this result:
sshg3 user@server#port "echo ""echo ""pwd;pwd""|lftp -u user3 -p 1234 server2""|sudo su - user2"
This prints:
echo pwd
bash: pwd|lftp -u user3 -p 1234 server2: command not found
The most part I got by using the answer in [this][1] thread - but now I am stuck.
Can someone help me with this?
"echo ""pwd;pwd""|sudo su - user2"is equivalent to"echo pwd;pwd|sudo su - user2"because of how the shell parses it. Did you mean\"? – Kamil Maciorowski Aug 24 '18 at 09:23lftp. But I know theseecho-s are awful. Do you needsuto provide you an interactive shell afterlftpfinishes? Something like this seems to be a way better syntax:sshg3 user@server#port 'sudo -u user2 -- lftp -u user3 -p 1234 -c "pwd; pwd" server2'. Untested though. – Kamil Maciorowski Aug 24 '18 at 09:50