1.
cmd = "Some unix command" Retcode = Subprocess.call (cmd,shell=true)
2.
SSH = Paramiko. Sshclient () ssh.connect (server, Username=username, Password=password) Ssh_stdin, ssh_stdout, Ssh_stderr = ssh.exec_ Command (Cmd_to_execute)
3.
Import Spurshell = Spur. Sshshell (hostname= "localhost", username= "Bob", password= "password1") result = Shell.run (["Echo", "-N", "Hello"]) print Result.output # Prints Hello
4.
Sshprocess = subprocess. Popen ([' ssh ', <remote client>], stdin=subprocess. PIPE, stdout = subprocess. PIPE) sshProcess.stdin.write ("ls mydirectory\n") sshProcess.stdin.write ("Echo end\n") for line in Stdout.readlines (): if line = = "end\n": Break print (line) sshProcess.stdin.write ("uptime\n") sshProcess.stdin.write ("Echo end\n") for L ine in Stdout.readlines (): if line = = "end\n": Break print (line)
This article from the "Linux and Network" blog, reproduced please contact the author!
Several ways Python calls the shell