Python Forum
Long command with characters not working in Python on Oracle Linux 7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Long command with characters not working in Python on Oracle Linux 7
#7
Below is the script I have with the command you suggested.

Output:
import paramiko from subprocess import list2cmdline import shlex client=paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) cmd = list2cmdline(shlex.split("find /OVS -wholename '*VirtualMachines/*/vm.cfg' -exec grep -H 'simple_' {} \; 2>/dev/null | awk {'print $3'} | tr -d \"'\"")) client.connect('XX.XX.XX.XX',22, username='XXXX', password='XXXX') output="" stdin, stdout, stderr = client.exec_command(cmd) print "ssh succuessful. Closing connection" stdout=stdout.readlines() client.close() print "Connection closed" print stdout print cmd for line in stdout: output=output+line if output!="": print output else: print "There was no output for this command"


So when I run the python as you can see there is no error. But the command did not return any output. And if you look at the command being printed its different than what is desired.

Error:
ssh succuessful. Closing connection Connection closed [] find /OVS -wholename *VirtualMachines/*/vm.cfg -exec grep -H simple_ {} ; 2>/dev/null | awk "{print $3}" | tr -d ' There was no output for this command
Reply


Messages In This Thread
RE: Long command with characters not working in Python on Oracle Linux 7 - by iaas_infra - Jul-18-2019, 03:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 803 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  How to use a variable in linux command in python code? ilknurg 2 1,630 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  Long-term stable source to get news headlines with Python? sandufi 4 1,971 Dec-23-2021, 09:48 AM
Last Post: sandufi
  How to transform from wide to long format in python shantanu97 1 1,668 Nov-21-2021, 11:53 AM
Last Post: buran
  use subprocess on linux\pi wwith a "grep " command korenron 2 8,163 Oct-19-2021, 10:52 AM
Last Post: DeaD_EyE
  Python syntax in Linux St0rmcr0w 2 53,372 Jul-29-2021, 01:40 PM
Last Post: snippsat
  Encrypting Oracle Passwords / Python Library for That? bmccollum 1 2,616 Jun-11-2021, 07:59 PM
Last Post: Larz60+
  Login to NordVPN on Linux with python script AGreenPig 2 6,045 Feb-09-2021, 10:44 AM
Last Post: AGreenPig
  how to run linux command with multi pipes by python !! evilcode1 2 6,422 Jan-25-2021, 11:19 AM
Last Post: DeaD_EyE
  Extract continuous numeric characters from a string in Python Robotguy 2 2,671 Jan-16-2021, 12:44 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020