The module subprocess in Python

Method II : Direct method

Inserting commands directly instead as string. This is something similar to the first method. You can simply put the commands directly into the function. Bookmark the Index page and read more about Python.

See the examples pasted below:

To get Kernel details: Eg 1["uname", "-a"])

To display disk usage details: Eg 2["df", "-h"])

Method III : Executing as Python script in a file with .py extension

Step 1 : SSH to server.
Step 2 : Create a file with .py extension.
Step 3 : Give x permission.

chmod +x

Step 4 : Create code like:

import subprocess
print "Total disk details using df command:"["df", "-h"])

Step 5 : Execute it:


You got it!!

Try it and let me know if you have any questions..

Post navigation

Arunlal Ashok

Operations Engineer at Endurance International Group. Linux lover. Like to play on Linux console. I started this blog to share and discuss Linux thoughts.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team
We like to travel. Our travelogues are published at Trip Mentor

Leave a Reply

Your email address will not be published. Required fields are marked *