AhmFM
AhmFM

Reputation: 1782

Weird output observed on executing ssh commands remotely over ProxyCommand

Team, I have two steps to perform:

  1. SCP a shell script file to remote ubuntu linux machine
  2. Execute this uploaded file on remote ubuntu linux machine over SSH session using PROXYCommand because I have bastion server in front.

Code:

scp -i /home/dtlu/.ssh/key.key -o "ProxyCommand ssh -i /home/dtlu/.ssh/key.key [email protected] -W %h:%p"  /home/dtlu/backup/test.sh lab@$k8s_node_ip:/tmp/

ssh -o StrictHostKeyChecking=no -i /home/dtlu/.ssh/key.key -o 'ProxyCommand ssh -i /home/dtlu/.ssh/key.key -W %h:%p [email protected]' lab@$k8s_node_ip "uname -a; date;echo "Dummy123!" | sudo -S bash -c 'echo 127.0.1.1 \`hostname\` >> /etc/hosts'; cd /tmp; pwd; systemctl status cachefilesd | grep Active; ls -ltr /tmp/test.sh; echo "Dummy123!" | sudo -Sv && bash -s < test.sh"

Both calls above are working fine. I am able to upload test.sh and also its running but what is bothering me is during the process am observe weird output being thrown out.

output:

/tmp. <<< expected
[sudo] password for lab: Showing one                 
Sent message type=method_call sender=n/a              destination=org.freedesktop.DBus object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 error=n/a

Root directory /run/log/journal added.
Considering /run/log/journal/df22e14b1f83428292fe17f518feaebb.
Directory /run/log/journal/df22e14b1f83428292fe17f518feaebb added.
File /run/log/journal/df22e14b1f83428292fe17f518feaebb/system.journal added.

So, I don't want /run/log/hournal and other lines which don't correspond to my command in sh.

Upvotes: 0

Views: 237

Answers (1)

Mark
Mark

Reputation: 4455

Consider adding -q to the scp and ssh commands to reduce the output they might produce. You can also redirect stderr and stdout to /dev/null as appropriate.

For example:

{
scp -q -i /home/dtlu/.ssh/key.key -o "ProxyCommand ssh -i /home/dtlu/.ssh/key.key [email protected] -W %h:%p"  /home/dtlu/backup/test.sh lab@$k8s_node_ip:/tmp/ 

ssh -q -o StrictHostKeyChecking=no -i /home/dtlu/.ssh/key.key -o 'ProxyCommand ssh -i /home/dtlu/.ssh/key.key -W %h:%p [email protected]' lab@$k8s_node_ip "uname -a; date;echo "Dummy123!" | sudo -S bash -c 'echo 127.0.1.1 \`hostname\` >> /etc/hosts'; cd /tmp; pwd; systemctl status cachefilesd | grep Active; ls -ltr /tmp/test.sh; echo "Dummy123!" | sudo -Sv && bash -s < test.sh"
} >&/dev/null

Upvotes: 1

Related Questions