Linux Shell Implementation Daemon Script _linux Shell

Source: Internet
Author: User

Embedded beginners, the first time to upload code. Yesterday did a UDHCPD and Udhcpc Guardian, currently only with Shell imitation writing, what method can do guardian?

#! /bin/sh
#进程名字可修改
pro_name=udhcpc
wlan=ra0 while
 
true;
 
#    get $pro_name number of processes with PS
  num= ' PS aux | grep ${pro_name} |  grep-v grep |wc-l '
#  Echo $NUM
#    less than 1, restart process
  if ["${num}"-lt "1"];then
    echo "${pro_name} was  Killed "
    ${pro_name}-I ${wlan}
#    greater than 1, kill all Processes, reboot
  elif [" ${num} "-gt" 1 "];then
    echo" more than 1 ${pro_name},killall ${pro_name} "
    killall-9 $PRO _name
    ${pro_name}-I ${wlan}
  fi
#    kill zombie Process
  num_stat= ' ps aux | grep ${pro_name} | grep T | grep-v grep | wc-l '
 
  if ["${num_stat}"-gt "0"];then
    Kil Lall-9 ${pro_name}
    ${pro_name}-I ${wlan}
  fi done
 
exit 0

The above is the entire contents of this article, I hope to be familiar with the Linux shell script to help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.