-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRefreshReadEKM.sh
executable file
·64 lines (59 loc) · 2.49 KB
/
RefreshReadEKM.sh
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
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
#
#
# GetArchiveTag.sh -- Shell script to kill and restart ReadEKM program every day at 0705.
# Copyright (C) 2015 Thomas A. DeMay
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# *
# */
#
# This script creates a special file in the user's home directory that the
# program looks for. When found, the program quits gracefully.
#
# Script is run in the source directory.
#
declare -i waitCount=20 # Will cause us to give up clean quit after 200 seconds.
# Get pid of ReadEKM process -- look for "ReadEKM" surrounded by word breaks.
# Not just "ReadEKM" because that could be in some other process.
# wpid is NOT empty if the ReadEKM application is running, and the status is true.
if wpid=$(ps -AcU"tom" | grep "\<ReadEKM\>")
then
touch $HOME/.CloseReadEKM # Create .CloseReadEKM file if not exist.
while wpid=$(ps -AcU"tom" | grep "\<ReadEKM\>")
do ## Wait for ReadEKM program to see .CloseReadEKM file and quit.
sleep 10
## But don't wait forever.
if [ $((--waitCount)) -lt 0 ]; then break; fi
done
fi
# if wpid is not empty, clean termination above did not work.
if [ -n "$wpid" ]; then
wpid=$(echo $wpid | cut -d" " -f1) # Extract the pid
kill $wpid # kill the process
rm $HOME/.CloseReadEKM # remove the .CloseReadEKM file
# so it won't kill the process
# immediately after starting.
# sleep for 10 seconds
sleep 10
fi
# Sleep till 1 sec after the next minute.
sleep $(( 61 - ( $(date -j +%s) % 60 ) ))
# restart ReadEKM program
#### MAKE SURE THERE IS A LINK TO THE CURRENT EXECUTABLE
#### WHERE THIS SCRIPT EXPECTS IT TO BE.
$PWD/ReadEKM 300002570 &
# Reschedule this script to run at 0705 tomorrow.
at -fRefreshReadEKM.sh 0705 >/dev/null 2>&1