偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Linux腳本分享:自動(dòng)關(guān)機(jī)與計(jì)算任務(wù)管理

系統(tǒng) Linux
本文分享的bash shell腳本用于實(shí)現(xiàn)Linux的自動(dòng)關(guān)機(jī),以及簡(jiǎn)單的計(jì)算任務(wù)管理??梢匝由鞂?shí)現(xiàn)其他功能,這里主要是提供一個(gè)實(shí)現(xiàn)思路。本文分享的腳本推薦使用screen來(lái)執(zhí)行。

編者按:本文分享的bash shell腳本用于實(shí)現(xiàn)Linux的自動(dòng)關(guān)機(jī),以及簡(jiǎn)單的計(jì)算任務(wù)管理。可以延伸實(shí)現(xiàn)其他功能,這里主要是提供一個(gè)實(shí)現(xiàn)思路。

1.自動(dòng)關(guān)機(jī)腳本

每隔一定時(shí)間檢測(cè)一次,如果不存在某個(gè)進(jìn)程就關(guān)機(jī),如果存在就休眠。

用法: ./腳本名 進(jìn)程名 休眠時(shí)間

注意:要有關(guān)機(jī)的權(quán)限(一般來(lái)說(shuō)是root用戶或者有sudoer權(quán)限)!

建議用法: screen ./腳本名 進(jìn)程名 休眠時(shí)間

#/bin/bash
 
while :
do
    thread_num=`ps -e |grep $1 | wc -l`
    if [ $thread_num -eq 0 ]; then
       date >> shutdowntime.log
       shutdown -h
       exit
   else
       echo "Sleeping $2 second..."
       sleep $2
   fi
done

2.計(jì)算任務(wù)管理腳本

簡(jiǎn)單的計(jì)算任務(wù)管理:檢測(cè)某個(gè)為某個(gè)名字的進(jìn)程的個(gè)數(shù),如果不是少于設(shè)定的個(gè)數(shù),就提交任務(wù),直到進(jìn)程數(shù)和設(shè)定的相等;如果進(jìn)程數(shù)大于等于設(shè)定個(gè)數(shù),就休眠一定時(shí)間。

用法:./腳本名 程序名 任務(wù)數(shù) 循環(huán)次數(shù)

建議用screen運(yùn)行。

#!/bin/bash
 
pro_name=$1
task_num=$2
cycle_num=$3
 
i=1
while (( $i <= $cycle_num ))
do
  pro_num=$(ps -A | grep $pro_name |wc -l)
 
  if (( $pro_num < $task_num )); then
    echo $i
    #在這里寫要執(zhí)行程序
    sleep 1s
    i=$(($i+1))
  else
    echo 'sleeping 600s'
    sleep 600s
  fi
done

另外,可以在循環(huán)中針對(duì)時(shí)段控制任務(wù)數(shù):

core_num=`cat /proc/cpuinfo |grep 'core id' | wc -l`
 
time_hour=`date +%H`
if (( $time_hour >= 23 )) || (( $time_hour < 7 ); then
     task_num=$core_num #晚上23:00以后到早上7點(diǎn)前這段時(shí)間,就按機(jī)器的core數(shù)來(lái)提任務(wù)
else
     task_num=$(( $core_num / 2 )) #其它時(shí)間只占用一半的core數(shù)來(lái)用于任務(wù)
fi

在執(zhí)行完后所有該做循環(huán)這后,也可以加上關(guān)機(jī)的命令。

原文:http://blog.sina.com.cn/s/blog_59cf67260100muoj.html

【編輯推薦】

  1. 幾個(gè)常用的Linux監(jiān)控腳本
  2. 不看后悔的Linux生產(chǎn)服務(wù)器Shell腳本分享
  3. 天外飛仙級(jí)別的Linux Shell命令
  4. 天外飛仙級(jí)別的Linux Shell命令(第二彈)
責(zé)任編輯:yangsai 來(lái)源: felonwan的博客
相關(guān)推薦

2011-09-02 10:29:30

腳本Linuxperl

2019-10-18 10:30:14

Windows 10自動(dòng)關(guān)機(jī)Windows

2011-08-08 16:49:07

自動(dòng)關(guān)機(jī)SwitchOffWindows

2012-05-16 14:13:03

Win7

2017-06-08 11:11:03

Windows 8Windows自動(dòng)關(guān)機(jī)計(jì)劃

2015-09-08 13:47:24

C#編寫自動(dòng)關(guān)機(jī)

2009-08-06 10:28:11

Vmware虛擬機(jī)自動(dòng)

2017-03-20 20:10:04

Windows 7Windows定時(shí)關(guān)機(jī)

2011-07-28 22:41:04

投影機(jī)技巧

2019-08-23 06:22:47

LinuxShell監(jiān)控腳本

2010-10-09 09:18:59

Shell腳本

2011-04-29 10:02:35

投影機(jī)

2021-11-17 22:41:41

手機(jī)電池低溫

2010-11-25 13:45:44

2022-03-01 20:26:12

PythonCSV腳本

2022-01-11 09:59:23

Python關(guān)機(jī)程序文件

2013-01-08 16:45:05

Android開發(fā)自動(dòng)開關(guān)機(jī)

2010-09-06 14:14:32

ppp-on

2021-01-27 07:56:04

Python編程語(yǔ)言

2019-08-12 07:45:44

Linux腳本shell
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)