• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

GCE Agent Bash

May 11, 2020

This is a Bash script to restart a service.

#!/bin/bash
 
SERVICE=google_osconfig_agent
AGENT=google-osconfig-agent
 
if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 ))
then
    echo "$AGENT service running, everything is fine"
else
    echo "$AGENT is not running"
    echo "Restarting service"
    systemctl start $AGENT
    sleep 5s
    if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 ))
    then
      sleep 2s
      echo "$AGENT service is now running"
    fi
fi

#!/bin/bash SERVICE=google_osconfig_agent AGENT=google-osconfig-agent if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 )) then echo "$AGENT service running, everything is fine" else echo "$AGENT is not running" echo "Restarting service" systemctl start $AGENT sleep 5s if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 )) then sleep 2s echo "$AGENT service is now running" fi fi

Filed Under: Cloud, Linux Tagged With: agent, bash, gce, restart

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023