0
1
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?
What is your local shell? I think
"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 – 2018-08-24T09:23:58.540Additionally I cannot tell what exactly you are trying to do. Maybe if I knew what "this thread" is... Please [edit] the question and at least fix the link. – Kamil Maciorowski – 2018-08-24T09:29:11.163
Still I'm not sure what the command should do and I have no experience with
lftp
. But I know theseecho
-s are awful. Do you needsu
to provide you an interactive shell afterlftp
finishes? 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 – 2018-08-24T09:50:33.943