-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSubmitOpenPermissions.sh
executable file
·108 lines (83 loc) · 1.91 KB
/
SubmitOpenPermissions.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
SCRIPT_NAME=$(basename "${0}")
DEFAULT_DIRECTORY=""
DEFAULT_AFTER_JOB_NUMBER=""
inform()
{
local msg=${1}
echo "${SCRIPT_NAME}: ${msg}"
}
get_options()
{
local arguments=($@)
# initialize global output variables
# set default values
g_directory="${DEFAULT_DIRECTORY}"
g_after_job_number="${DEFAULT_AFTER_JOB_NUMBER}"
# parse arguments
local num_args=${#arguments[@]}
local argument
local index=0
while [ ${index} -lt ${num_args} ]; do
argument=${arguments[index]}
case ${argument} in
--directory=*)
g_directory=${argument/*=/""}
index=$(( index + 1 ))
;;
--dir=*)
g_directory=${argument/*=/""}
index=$(( index + 1 ))
;;
--after-job-number=*)
g_after_job_number=${argument/*=/""}
index=$(( index + 1 ))
;;
*)
inform "Unrecognized option: ${argument}"
exit 1
;;
esac
done
local error_count=0
# check parameters
if [ -z "${g_directory}" ]; then
inform "--directory= or --dir= required"
error_count=$(( error_count + 1 ))
else
inform "directory: ${g_directory}"
fi
if [ ! -z "${g_after_job_number}" ]; then
inform "After Job Number: ${g_after_job_number}"
fi
if [ ${error_count} -gt 0 ]; then
inform "ABORTING"
exit 1
fi
g_job_logs_dir=${HOME}/joblogs
}
main()
{
get_options "$@"
local script_file_to_submit
local submit_cmd
local job_no
local date_string
date_string=$(date +%s)
script_file_to_submit="${HOME}/submit_scripts/OpenPermissions-${date_string}.sh"
cat > ${script_file_to_submit} <<EOF
#PBS -o ${g_job_logs_dir}
#PBS -e ${g_job_logs_dir}
chmod --recursive --verbose 777 ${g_directory}
EOF
chmod +x ${script_file_to_submit}
submit_cmd="qsub"
if [ ! -z "${g_after_job_number}" ]; then
submit_cmd+=" -W depend=afterany:${g_after_job_number}"
fi
submit_cmd+=" ${script_file_to_submit}"
job_no=$(${submit_cmd})
inform "job_no: ${job_no}"
}
# Invoke the main function to get things started
main $@