-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_executor.sh
More file actions
37 lines (30 loc) · 821 Bytes
/
auto_executor.sh
File metadata and controls
37 lines (30 loc) · 821 Bytes
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
#!/bin/bash
script_name=""
period=""
for arg in "$@"
do
case $arg in
--script_name=*)
script_name="${arg#*=}"
;;
--period=*)
period="${arg#*=}"
;;
esac
done
if [ -z "$script_name" ] || [ -z "$period" ]; then
echo -e "\033[31m[ERROR] --script_name and --period cannot be none\033[0m"
exit 1
fi
script_name="${script_name%.sh}"
log_file="/tmp/pal-$script_name.log"
script_name="$script_name.sh"
current_path=$(dirname "$(readlink -f "$0")")
script_name="$current_path/$script_name"
echo "Restart script name: $script_name, Period: $period"
chmod +x "$script_name"
cron_job="$period /bin/bash $script_name >> $log_file 2>&1"
#echo "$cron_job"
if ! crontab -l | grep -Fq "$script_name"; then
(crontab -l 2>/dev/null; echo "$cron_job") | crontab -
fi