Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write Shell script to restart Centos system in a gentle way

Shulou Source: shulou.com Published: 2022-06-03 09:19:10 09月14日 Update

This article introduces the knowledge of "how to write a Shell script to restart the Centos system in a gentle way". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The main purpose is to restart important processes in the background. If you use killall-9 to force kill to drop, it may cause problems. Such as database processes. The code is as follows:

The code is as follows:

#! / bin/sh

If [- z "$1"]; then

/ bin/echo "$0"

Exit 1

Fi

Param=''

List='2 3 4 5 6 7 8 9'

For i in $list; do

Eval packs are not available.

If [- z $p]; then

Break

Fi

Param= "$param $p"

Done

If [- f / bin/awk]; then

AWK=/bin/awk

Else

AWK=/usr/bin/awk

Fi

If [- f / bin/grep]; then

GREP=/bin/grep

Else

GREP=/usr/bin/grep

Fi

Program= `/ bin/echo $1 | $AWK-F'/'{print $NF;}'`

Count= `/ bin/ps auxww | $GREP-w $program | $GREP-v grep | / usr/bin/wc-l`

If [$count-gt 0]; then

ITunes 0

/ bin/echo "stopping $program..."

While [1-eq 1]; do

If [$I-eq 0]; then

/ usr/bin/killall $program

Else

/ usr/bin/killall $program > / dev/null 2 > & 1

Fi

If [$?-ne 0]; then

Break

Fi

/ usr/bin/printf.

/ bin/sleep 1

Let i=$i+1

Done

Fi

/ bin/echo ""

Count= `/ bin/ps auxww | $GREP-w $program | $GREP-v grep | $GREP-v $0 | / usr/bin/wc-l`

If [$count-eq 0]; then

/ bin/echo "starting $program..."

Exec $1$ param

Else

/ bin/ps auxww | $GREP-w $program | $GREP-v grep | $GREP-v $0

/ bin/echo "already running $program count: $count, restart aborted!"

Fi

This is the end of "how to write a Shell script to gently restart the Centos system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Moderate way system script code content more knowledge process practical important learned next background dilemma actual situation data database article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MySQL Microsoft Shulou Tech Info MariaDB