Command execution trouble

Mar 21, 2013 at 11:49 PM
I am trying to send a command through sshNET:

if [ $(pgrep -f 'SCREEN -S burnintest_screen') ]; then echo Success; fi

On my linux host, this command results in Success when the command is issued directly from the command line (As long as SCREEN is running with the selected command line). If the SCREEN command isn't running, it results in nothing.

When sent via sshNET, it always results in nothing returned.

if [ "$(pgrep -f 'SCREEN -S burnintest_screen')" ]; then echo Success; fi

or

bash -c "if [ \"$(pgrep -f 'SCREEN -S burnintest_screen')\" ]; then echo Success; fi"

These behave the expected way directly from the command line but always results in Success when issued via sshNET.

Encoding is UTF8 (I've tried ASCII as well). The user's shell is bash. I've tried both the RunCommand() and cmd.Execute() approaches.

Any idea what might be happening?

Thanks,

Robert
Mar 22, 2013 at 5:47 PM
I like replying to myself.... This is just my misunderstanding of how sshNET works. Normally, pgrep will not detect itself. But, the execute (or run command) method results in a "bash -c" process being spawned on the host. That appears to keep pgrep from eliminating its own process in its results.
Mar 22, 2013 at 5:59 PM
Sending

[ "$(pgrep -f 'SCREEN -S [burnintest_screen]')" ] && echo Success

through the execute method will prevent re-matching the pgrep command line as pgrep's search pattern is a regular expression. Done!