-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeep_run
More file actions
executable file
·79 lines (67 loc) · 1.85 KB
/
Copy pathkeep_run
File metadata and controls
executable file
·79 lines (67 loc) · 1.85 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Name: keep_run
# Description:
# This script will ensure that the program run successfully.
# If the program run failed, it will automatically re-run again.
#
# Example:
# # work as a script
# bash keep_run run_ideas_test.sh \
# "ls */*/*pdf | wc -l" "30" \
# "qstat | grep node | wc -l" "1"
#
# # work as a command
# keep_run run_ideas_test.sh \
# "ls */*/*pdf | wc -l" "30" \
# "qstat | grep node | wc -l" "1"
######################################################################
####### get parameters #######
# Re-run script.
script=$1
# Set the command to check whehter the program is end. Using quote for the command, eg "qstat | grep node | wc -l".
task_status_command=$2
# If the program end, the output of task_status_command, eg 1
task=$3
# Set the command to check whehter the target is successful. Judge results from the status code. Using quote for the command, eg "ls */*/*pdf | wc -l".
target_status_command=$4
# If getting target aims successfully, the output of target_status_command, eg 30
target=$5
##############################
####### define some settings #######
i=1
root=$(dirname $script)
####################################
############################ Uninterrupted monitoring ############################
while ture
do
# whether the job have ended?
result1=$(echo $task_status_command | bash)
if [[ $result1 == $task ]]; then
# ended job
condition1=1
else
# unended job
condition1=0
fi
# whether the job have succeed?
result2=$(echo $target_status_command | bash)
if [[ $result2 == $target ]]; then
# successful job
condition2=0
else
# failed job
condition2=1
fi
# ended job
if [[ $condition1 -eq 1 ]]; then
if [[ $condition2 -eq 1 ]]; then
# failed job
bash ${script} 1>${root}/std_${i}.out 2>${root}/err_${i}.out
((i++))
else
# successful job
break
fi
fi
sleep 300
done