Executing a command thru ssh using pseudo terminal: do not close connection if command is not found

user3541631

I want to write a small script to automate some commands in python for unix and linux, thru pexpect.

Ex:

ssh -t [email protected] "uname -r && some_cmd_that_exist_or_not && exec /bin/sh"

The problem, is that I don't know from the beginning what type of the OS the machine has, and in some cases the commands are not available.

In this case the connection is closed and a "command not found is returned". I want to continue executing even if a command is not found.

After that I retrive the output using pyexpect. My issue is that I couldn't find an option to keep the connection open if a commad is not found.

William Pursell

Just replace the && with ;:

ssh -t [email protected] 'uname -r; some_cmd_that_may_not_exist; exec /bin/sh'

The && is a short-circuiting operator, so it will stop executing commands as soon as any of the commands fail. If you want to run them all, just don't use it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ssh command not found in terminal

Getting "Pseudo-terminal will not be allocated because stdin is not a terminal" when executing command in SSH.NET

Closing connection after executing reboot using ssh command

ssh detach remote command with pseudo terminal

remotely executing a command using ssh

Executing a remote command on SSH connection, before login

Getting ksh: NF: not found on executing ssh command

Command not found via ssh with single command, found after connecting to terminal

How do I change my path when executing a command following a terminal ssh to another machine

Using jcraft official demo to do ssh connection but get 'zsh:1: command not found: roscore exit-status: 127'

Using alias by executing command remotely with ssh

Executing reboot command over SSH using Paramiko

ssh: terminal problem when executing command on remote server

CURL command not executing in SSH

Debugging SSL connection using openssl terminal command

when executing SSH command from jenkins nvm not found

lessc: command not found (terminal)

mvn: command not found - terminal

java command not found in terminal

Will a query which may take hours to execute keep executing on remote server if I close the connection after executing the command?

Problem using child-process vs terminal while executing a command

Command is not found using `ssh root@host command`

Executing command using "su -l" in SSH using Python

Chroot SSH - Command not found

ssh localhost command not found

Windows Batch: Executing command with FOR /F -- "command not found"

ssh - close connection but keep executing remotely

Executing a command using JSch

Executing SSH command over list of IP addresses (using Paramiko)