I need to use an if statement that is true only if "is loaded" AND "is running" occur in a service status command output:
$groupservice status
service 1 is loaded
service 2 is running
As already mentioned I've tried to use this:
$service status | awk '/is loaded/ && /is running/'
but I dont' get any output. The only way to run it is in this way:
if [[ $(service status | grep "is loaded") ]] && [[ $(service status | grep "is running") ]]
but I'd prefer to use a shorter expression. Where am I wrong? thank you
awk
attempt is thatawk
processes the input line-wise, so your program would only work ifis loaded
andis running
appeared on the same line. Also, you say "As already mentioned" - can you add a link where you mentioned this? – AdminBee Jul 05 '21 at 10:04groupservice status|sed '/is loaded/!d;N;/is running/!d'
? – Philippos Jul 05 '21 at 10:10