I am basically trying to see if a service is running and, if not, then start the service. Everything seems to work fine if the service is not running; however, when the service is running, the exact same if condition complains about syntax issues. Here's my example below:
# systemctl status redis-server@openvas.service
redis-server@openvas.service - Advanced key-value store (openvas)
Loaded: loaded (/usr/lib/systemd/system/redis-server@.service, disabled)
Active: inactive (dead)
# if [ ! $(systemctl status redis-server@openvas.service | grep -i "active: active") ]; then systemctl start redis-server@openvas.service; fi
# systemctl status redis-server@openvas.service
redis-server@openvas.service - Advanced key-value store (openvas)
Loaded: loaded (/usr/lib/systemd/system/redis-server@.service, disabled)
Active: active (running)
# if [ ! $(systemctl status redis-server@openvas.service | grep -i "active: active") ]; then systemctl start redis-server@openvas.service; fi
bash: [: active: binary operator expected
#
How is there a syntax issue all of a sudden if the same command is run before and has no problems?