0

i need to write a bash script to check a service status.

I need to look in the command output; /etc/init.d/ipsec status

The line "1 tunnels up" indicates the service is up.

If the line is not part of the command output i need to restart the service.

Searching in the net there are some examples but searching for service pid, so i can't find an example for this particular case

Any help to do this script?

1 Answer 1

1

you could use grep not tested but it would look like this

service ipsec status | grep "1 tunnels up" 
RET=$?
if [ ! $RET -eq 0 ];then
    echo "[!] No tunnels up, better restart"
    service ipsec restart
fi
1
  • thank you, I had started well with "service ipsec status | grep " 1 tunnels up " but I did not know how to continue .
    – user56673
    Apr 5, 2016 at 14:59

You must log in to answer this question.