防止shell script多次运行
一个思路是在script初期检测系统中是否存在同名进程。
if [ `ps -ef | grep "test.sh" | grep -v "grep" | wc -l` -gt ]
then
echo "This script is already running. Exit."
else
while true
do
echo "I am running"
sleep
done
fi
如果是第一次运行,那么首行语句检测到的同名进程会有两个:第一个是启动这个script的进程,第二个是反引号内的命令。
防止shell script多次运行的更多相关文章
- shell script练习
执行脚本的几种方式: 1. sh a.sh 或者 bash a.sh 调用的是 /bin/bash 进程执行的,所以脚本不需要执行权限. 2. 直接使用绝对路径执行, /home/script/a ...
- 这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script
这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script ##转载注明出处:http://www.cnblogs.com/wade-xu/p/4378224.html ...
- shell script 的追踪与 debug
shell script 的追踪与 debug scripts 在运行之前,最怕的就是出现语法错误的问题了!那么我们如何 debug 呢?有没有办法不需要透过直接运行该 scripts 就可以来判断是 ...
- 第十三章、学习 Shell Scripts 简单的 shell script 练习
简单的 shell script 练习 简单范例 对谈式脚本:变量内容由使用者决定 [root@www scripts]# vi sh02.sh #!/bin/bash # Program: # Us ...
- shell script中的$*和$@
在shell script中,$*和$@都是获取所有的命令行参数,但是这两者在使用的过程中会有细微的差别,差别主要是在有没有使用双引号,即是直接使用$*,$@,还是使用"$*",& ...
- shell script 入门 笔记
shell script 入门 在 shell script 注意必须使用完全相同写在下面: 1. 指令的运行是从上而下.从左而右的分析与运行: 2. 指令的运行就如同第五章内提到的: 指令.选项 ...
- 菜鸟教程之学习Shell script笔记(下)
菜鸟教程Shell script学习笔记(下) 以下内容是学习菜鸟教程之shell教程,所整理的笔记 菜鸟教程之shell教程:http://www.runoob.com/linux/linux-sh ...
- 菜鸟教程之学习Shell script笔记(中)
菜鸟教程Shell script学习笔记(中) 以下内容是学习菜鸟教程之shell教程,所整理的笔记 菜鸟教程之shell教程:http://www.runoob.com/linux/linux-sh ...
- 菜鸟教程之学习Shell script笔记(上)
菜鸟教程之学习Shell script笔记 以下内容是,学习菜鸟shell教程整理的笔记 菜鸟教程之shell教程:http://www.runoob.com/linux/linux-shell.ht ...
随机推荐
- db.properties是干什么用的
连接池配置文件db.properties是java中采用数据库连接池技术完成应用对数据库的操作的配置文件信息的文件.具体配置项目如下:drivers=com.microsoft.sqlserver.j ...
- Oracle CONNECT by 简单用法
Oracle查询层级的 一个表里 通过一个parentid连接 select * FROM A_MERIATILA start with id=520 CONNECT by prior id=PAR ...
- winform 写入txt(可以连续性的在文本内容后面追加)
在上一篇写入txt的时候,不可以在后面追击,调用一次,以前的同名的文本就会覆盖掉.这次的功能会修改上次这个小bug StreamWriter sw = new StreamWriter("D ...
- leetcode题解 7.Reverse Integer
题目: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 E ...
- java DOM
使用DOM解析XML文档的步骤 1.创建解析器工厂对象 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 2 ...
- vue中 左侧导航条 多个toggleClass
<ul> <li v-for='item in items' @click="showToggle(item)"> <i :class="{ ...
- svg的使用集合
1.效果 https://www.zhangxinxu.com/wordpress/2017/03/offset-path-css-animation/ 2.用法 https://www.cnblog ...
- Altium Designer 10 使用技巧
一.封装文件.PCB文件编辑时的吸附(Snap)的灵敏度. 像焊盘中心.过孔中心.线段的端点.走线的端点.铺铜的顶点,这样的点有吸附光标的特性,鼠标移动到这些点的附近会被吸附到上面.Snap的灵敏度可 ...
- Sql 查询当天、本周、本月记录、上周、上月记录
查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 查询24小时内: select * from info where D ...
- JS之clientX,clientY,screenX,screenY,offsetX,offsetY区别
首先需要知道clientX,clientY,screenX,screenY,offsetX,offsetY 是鼠标事件对象下的几个属性. 之前也一直对这些属性搞的稀里糊涂,看文档上说的也是不太理解,反 ...