#!/bin/sh
# **************************************************
# * * * Libraries
# **************************************************
Source/etc/profile;
Sleep 2
Date= ' date + '%f_%h:%m '
If [x$1!= "X"]
Then
Date=$1
Fi
Echo $DATE
Basedir= ' DirName $ '
CD $BASEDIR
#######################################################
tmpfile= $BASEDIR/isrunning.tmp
Echo $TMPFILE
# begin--Check if there are any other instances running to ensure that only one instance can be run at the same time
If [f $TMPFILE];then #判断临时文件是否存在www. linuxidc.com
echo "Other instance is running!" #存在表明有一个实例在运行
Exit 0 #退出本脚本的执行
Else
Touch $TMPFILE #监时文件若不存在, use your touch to create a new
chmod $TMPFILE #把临时文件属性改为只建立者可读写
Fi
#用 Trap command to set up a listener to the signal
#程序运行中当监听到信号 0,1,2,3,9,15 Deletes the temporary file and exits the script execution
#比如说, when the script ends itself, the user Ctrl + C drops, gets killed, and the terminal is closed
#系统关机或重启的情况下, you need to delete the temporary files, otherwise the script will not be able to execute
#在 Linux Shell can run trap-l check to see so the signal
Trap "Rm-f ${tmpfile}; Exit "0 1 2 3 9 15
# end--Check if there are any other instances running to ensure that only one instance can be run at the same time