Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

start a service in bash if stopped

#!/bin/bash
SERVICE="nginx"
if pgrep -x "$SERVICE" >/dev/null
then
    echo "$SERVICE is running"
else
    echo "$SERVICE stopped"
    # uncomment to start nginx if stopped
    # systemctl start nginx
    # mail  
fi
Comment

bash only start a service if not running

#!/bin/bash
service=replace_me_with_a_valid_service

if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running!!!"
else
/etc/init.d/$service start
fi
Comment

PREVIOUS NEXT
Code Example
Shell :: alfred intellij toolbox 
Shell :: upgrade all content database sharepoint 2013 powershell 
Shell :: linux subsystem mount file into windows 
Shell :: change file permissions ssh 
Shell :: add string at the end of each line 
Shell :: convert x-ray dicom to png 
Shell :: connect different volumes docker container 
Shell :: echo with tee command 
Shell :: start confluence service ubuntu 
Shell :: zsh-autosuggestions 
Shell :: node-gyp rebuild error ubuntu 20.04 
Shell :: pip install apyori 
Shell :: ls -la sort time file 
Shell :: add yarn package globally 
Shell :: format of functions in bash shell script 
Shell :: colcon build single package 
Shell :: git remote add origin 
Shell :: uninstall nignx 
Shell :: git remove submodule 
Shell :: conda install kneed 
Shell :: how to remove pkg from mac 
Shell :: rec: command not found 
Shell :: how to create a script raspberry pi 
Shell :: git tag older commit 
Shell :: set sublime text as git editor mac 
Shell :: replace match in various grep match 
Shell :: install go on mac brew 
Shell :: UnicodeDecodeError 
Shell :: powershell function resize image 
Shell :: git passphrase remember 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =