I need to monitor services in rhel 8
below are the service......
crond
chronyd
rsyslogd
sshd
sssd
firewalld
Scripts..........
#!/bin/bash
for i in "${SERVICES[@]}"
do
###CHECK SERVICE####
`pgrep $i `
STATS=(echo $?)
if [ $STATS == 0 ]
then
echo "$i is running"
else
echo "$i is not running"
fi
done
but after run script, output does not come. please help, where is the problem in scripts.
--- Post updated at 07:17 PM ---
I prepared another script. but getting error.
#!/bin/bash
for i in `cat SERVICES`
do
###CHECK SERVICE####
status=systemctl | grep running |grep $i |awk '{print $4}'
if [ $status -eq running ]
then
echo "$i is running"
else
echo "$i is not running"
fi
done
Output-
[root@localhost ~]# sh service1.sh
service1.sh: line 6: [: -eq: unary operator expected
crond is not running
service1.sh: line 6: [: -eq: unary operator expected
chronyd is not running
service1.sh: line 6: [: -eq: unary operator expected
rsyslogd is not running
service1.sh: line 6: [: -eq: unary operator expected
sshd is not running
service1.sh: line 6: [: -eq: unary operator expected
sssd is not running
service1.sh: line 6: [: -eq: unary operator expected
firewalld is not running
Why it is coming error.