-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjob_linux.sh
More file actions
executable file
·52 lines (43 loc) · 1.19 KB
/
job_linux.sh
File metadata and controls
executable file
·52 lines (43 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
#This bash script use the PID method to prevent duplicate run of the main.py
#See the following link for more information about the PID method
#http://bencane.com/2015/09/22/preventing-duplicate-cron-job-executions/
#This bash script can be launched thanks to the crontable program.
#exemple: 0 20 * * * ~/job_linux.sh
#will run the joblinux.sh every day at 8pm and no more than one instance can run at a time thanks to this bash script.
pidfilename="/job_linux.pid"
mainScript="/main.py"
logger="/activity.log"
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo $BASEDIR
PIDFILE=$BASEDIR$pidfilename
echo $PIDFILE
if [ -f $PIDFILE ]
then
PID=$(cat $PIDFILE)
ps -p $PID > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Process already running"
exit 1
else
## Process not found assume not running
echo $$ > $PIDFILE
if [ $? -ne 0 ]
then
echo "Could not create PID file"
exit 1
fi
fi
else
echo $$ > $PIDFILE
if [ $? -ne 0 ]
then
echo "Could not create PID file"
exit 1
fi
fi
#Run the python script main.py
python $BASEDIR$mainScript
rm $PIDFILE
#mail -s “logger_Sentinel” n.debonnaire@gmail.com < $BASEDIR$logger