zoukankan      html  css  js  c++  java
  • 简单的csh实例

    通过flag文件来检测与否在运行。

    可以加入相关关键字的进程的检测。 

    代码:(简单的csh实例)running_check

    #!/bin/csh -f

    if ($#argv < 2 ) then
    usage:
      echo "Usage: $0 <running_flag> <action> <timeout>"
      echo "action need be one value of -check or -delete."
      echo "default timeout is 0, it means no timeout limitation."
      exit 1
    endif

    set running_flag = $1
    set action = $2
    set timeout = 0
    if ( "$3" != "") set timeout = $3
    if ( "$action" != "-check" && "$action" != "-delete" ) goto usage

    # wait until the flag is deleted by ohter processes or timeout.
    set waittime = 0
    if ("$action" == "-check" && -e $running_flag ) then
      echo "running flag is existed, please wait!"
      set running = 1
      set sleeptime = 60
      while(("$timeout" != "0" && $waittime < $timeout) && $running \
            || "$timeout" == "0" && $running)
        echo "sleep $sleeptime" && sleep $sleeptime
        @ waittime += $sleeptime
        if (! -e $running_flag) set running=0
      end
    endif

    # timeout, delete the flag.
    if ("$timeout" != "0" && "$waittime" >= "$timeout") then
      echo "timeout $timeout"
      echo "delete running flag"
      if ( -e $running_flag) rm $running_flag
    endif


    # if check, set new flag.
    # if delete, delete the flag.

    if ( "$action" == "-check" ) then
      echo "touch running flag"
      touch $running_flag
      echo `date` > $running_flag
      ls -l $running_flag
    else
      echo "delete running flag"
      if ( -e $running_flag) rm $running_flag
    endif
    exit 0

    完! 

  • 相关阅读:
    python类的特殊成员和方法
    python 之 staticmethod,classmethod,property的区别
    启动Android模拟器问题集锦
    eclipse编译Jmeter源码
    解决 'chromedriver' executable needs to be in PATH.'报错
    登录程序优化
    通过标志位跳出多层循环
    crontab计划任务监控nginx服务器
    httpstatus类的状态有哪些
    python正则表达式
  • 原文地址:https://www.cnblogs.com/itech/p/2698406.html
Copyright © 2011-2022 走看看