ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Just in testing the above does not work, it won't even print the output. I was thinking along the lines of.. if the above worked, could I just assume that 'output' is a variable in it's own right?
If that's the case, can I use python to manipulate the content? Like in shell scripts I would just use grep, awk and sed to manipulate the content of the returned data from the ssh session.
NID (HEX) NODENAME TYPE STATUS MODE
345 0x159 c1-0c2s6n1 compute admindown batch
385 0x181 c2-0c0s0n1 service down batch
577 0x241 c3-0c0s0n1 service down batch
1487 0x5cf c7-0c2s3n3 compute admindown batch
1730 0x6c2 c9-0c0s0n2 compute down batch
1731 0x6c3 c9-0c0s0n3 compute admindown batch
2497 0x9c1 c13-0c0s0n1 compute down batch
2529 0x9e1 c13-0c0s8n1 compute admindown batch
2780 0xadc c14-0c1s7n0 compute admindown batch
3205 0xc85 c16-0c2s1n1 compute admindown batch
3207 0xc87 c16-0c2s1n3 compute admindown batch
None
I'm getting "None" at the bottom, which I guess is the output from "print output" - But I thought "print output" would be the statement delivering the actual output, which is indeed displayed.
When I add some extra criteria to the grep command using egrep, things stop working:
I've played with what feels like a million variations of "s, 's, and )s etc, and tried splitting the string up somewhat, but I can't seem to get it to work.
Inevitably I don't actually want the above table to display, I just want to extract column 3 out of it and store in a variable or something, so that I can check some log files against the node names which are down.
Any pointers in the right direction are greatly appreciated
Looks like you posted this while I was typing my below comment. Thank you for this, I will read through it now and see if it helps me get closer to my goal.
So, I'm picking up from this that maybe it would be better to use a couple of processes to achieve this?
P1 to run the first command, and P2 to process the output of the command and return the desired results.. or have I picked up the wrong vibe from what you're suggesting?
I 'sort of' understand what's going on. But I wouldn't say it's overly clear.
Am I wandering the right lines?
Thanks,
Jon
EDIT:
It doesn't work. It's likely formatting and/or syntax. But is my thought process correct?
Code:
Traceback (most recent call last):
File "./test.py", line 9, in <module>
stdout=subprocess.PIPE)
File "/usr/lib64/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Last edited by jonnybinthemix; 02-09-2017 at 04:19 AM.
p1 = subprocess.Popen([something here, the first command],
stdout=subprocess.PIPE)
p2 = subprocess.Popen([something here, the second command],
stdin=p1.stdout,
stdout=subprocess.PIPE)
p3 = subprocess.Popen([something here, the third command],
stdin=p2.stdout,
stdout=subprocess.PIPE)
out, err = p3.communicate()
and actually in your first Popen you need not use ":
p1 = subprocess.Popen([something here, the first command],
stdout=subprocess.PIPE)
p2 = subprocess.Popen([something here, the second command],
stdin=p1.stdout,
stdout=subprocess.PIPE)
p3 = subprocess.Popen([something here, the third command],
stdin=p2.stdout,
stdout=subprocess.PIPE)
out, err = p3.communicate()
and actually in your first Popen you need not use ":
I apologise if I'm slow to pick up the basics here, but I'm trying to make sure I fully understand things. I'd much rather learn how it works, than just get it working if you know what I mean
Thanks
Jon
Last edited by jonnybinthemix; 02-09-2017 at 04:52 AM.
Traceback (most recent call last):
File "./test.py", line 12, in <module>
stdout=subprocess.PIPE)
File "/usr/lib64/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
sorry guy, but without seeing your code I cannot say anything. It is in test.py, line 12, or somewhere near...
probably you missed a ) this time, please check your code carefully. You can try something like this: http://infoheap.com/python-lint-online/ to check your code
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.