简单的csh实例
来源:互联网 发布:linux培训北京 编辑:程序博客网 时间:2024/06/05 07:11
通过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
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
完!
- 简单的csh实例
- csh 语法实例参考
- csh简单语法
- csh简单语法
- csh简单语法
- csh的本地配置
- Csh的使用
- 切换csh的方法
- Csh的使用
- csh
- csh
- linux shell csh语法实例参考
- csh提供的电子书目录
- 【PDF】csh 命令的基本概念
- Bash与Csh的区别
- 配置你的 csh/tcsh
- 配置你的 csh/tcsh
- csh下的自动补齐
- Linux运行与控制后台进程的方法:nohup, setsid, &, disown, screen
- Linux的nm查看动态和静态库中的符号
- Perl eval函数探讨
- perl的logwrapper
- perl常量+多维数组+变量的初始化
- 简单的csh实例
- perl-cgi基础
- perl-cgi-form
- web开发在线调试
- perl-cgi命令行调试
- perl中调用cgi
- 11gr2exp/imp导入导出功能
- html的header结构和实例
- perl-cgi高级