Stop apache service remotely

The above is completely unnecessary, if you have

while read -r server
#[...]
done < server.txt

for status - what status, where do you pass the status variables to the script?
(/bin/bash is missing -s $list_of_statuses - unquoted if you intend to use word splitting)
Is a "for loop" even necessary? Do you understand what it's normally used for?

Are you sure, you don't need to read our previous replies again? From this thread...

echo 3 | sudo tee systemctl status httpd > web.log; - this line creates 3 files in your current working directory: systemctl, status and httpd, all owned by root and containing 3; web.log will also contain stdout from sudo tee ... execution (it DOES NOT generate status from systemctl) - so all files will contain just a number 3.
You're better of running sudo systemctl status httpd &> web.log; instead of echo 3 | sudo tee systemctl status httpd > web.log;.

Did you mean if grep -q "Inactive" web.log; (otherwise why are you overwriting web.log with a null output from grep -q - that is, even if you first provided any stdin to it, because it won't work without a filename provided as an argument)

1 Like