Saturday, 15 August 2015

bash - If structure to compare result of two commands -



bash - If structure to compare result of two commands -

i want compare result of 2 commands in bash so:

if `cat /root/pid` == `ps aux | grep "python" | grep -v grep | awk '{print $2}'` <somecommands> else <othercommands> fi

i want check if result of cat /root/pid , ps aux | grep "python" | grep -v grep | awk '{print $2}' equal or not.

i want check if specific command running in server or not. method think works. other methods welcome.

thank you

you can use:

[[ "$(cat /root/pid)" == "$(ps aux | grep 'python' | grep -v grep | awk '{print $2}')" ]]

though believe can cutting downwards both grep , using awk itself.

bash if-statement

No comments:

Post a Comment