Run command using rsh on a remote computer

4k views Asked by At

I am trying to run a python script, and I need to Rsh a command from the script, the command I want to run is : df -Pk|grep "sd\|md"|gawk '{print $2}'

and I do it as -

cmd2='df -Pk|grep \\\"sd\|md\\\"|gawk \'{print $2}\''
process = subprocess.Popen(['rsh',ip,cmd2],stdout=subprocess.PIPE)
output = process.communicate()[0]

However when I do run the script,I get nothing in output.

I am new to python and as far as I know, its a problem with the escape characters.

Any help would be great.

Note: I have to use Rsh only and cannot use ssh

Thanks

1

There are 1 answers

5
Fred Foo On

Enclose the command, with proper shell quoting, in triple quote marks:

"""df -Pk|grep "sd\|md"|gawk '{print $2}'"""

See also the Python tutorial's bit on strings.