|
1 | | -#!/bin/bash |
2 | | -# info: add cron job |
3 | | -# options: user min hour day month wday command [job] |
4 | | -# |
5 | | -# The function adds a job to cron daemon. When executing commands, any output |
6 | | -# is mailed to user's email if parameter REPORTS is set to 'yes'. |
7 | | - |
8 | | - |
9 | | -#----------------------------------------------------------# |
10 | | -# Variable&Function # |
11 | | -#----------------------------------------------------------# |
12 | | - |
13 | | -# Argument defenition |
14 | | -user=$1 |
15 | | -min=$2 |
16 | | -hour=$3 |
17 | | -day=$4 |
18 | | -month=$5 |
19 | | -wday=$6 |
20 | | -command=$(echo $7 | sed -e "s/'/%quote%/g") |
21 | | -job=$8 |
22 | | - |
23 | | -# Includes |
24 | | -source $VESTA/conf/vesta.conf |
25 | | -source $VESTA/func/main.sh |
26 | | - |
27 | | -# Assing new value |
28 | | -A7="$command" |
29 | | - |
30 | | - |
31 | | -#----------------------------------------------------------# |
32 | | -# Verifications # |
33 | | -#----------------------------------------------------------# |
34 | | - |
35 | | -check_args '7' "$#" 'user min hour day month wday command [job]' |
36 | | -validate_format 'user' 'min' 'hour' 'day' 'month' 'wday' 'command' |
37 | | -is_system_enabled $CRON_SYSTEM |
38 | | -is_object_valid 'user' 'USER' "$user" |
39 | | -is_object_unsuspended 'user' 'USER' "$user" |
40 | | -is_package_full 'CRON_JOBS' |
41 | | -get_next_cronjob |
42 | | -validate_format 'job' |
43 | | -is_object_free 'cron' 'JOB' "$job" |
44 | | - |
45 | | - |
46 | | -#----------------------------------------------------------# |
47 | | -# Action # |
48 | | -#----------------------------------------------------------# |
49 | | - |
50 | | -# Concatenating cron string |
51 | | -str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'" |
52 | | -str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'" |
53 | | - |
54 | | -# Adding to crontab |
55 | | -echo "$str" >> $VESTA/data/users/$user/cron.conf |
56 | | - |
57 | | -# Chaning permissions |
58 | | -chmod 660 $VESTA/data/users/$user/cron.conf |
59 | | - |
60 | | -# Sort jobs by id number |
61 | | -sort_cron_jobs |
62 | | - |
63 | | -# Sync cronjobs with system crond |
64 | | -sync_cron_jobs |
65 | | - |
66 | | - |
67 | | -#----------------------------------------------------------# |
68 | | -# Vesta # |
69 | | -#----------------------------------------------------------# |
70 | | - |
71 | | -# Increasing cron value |
72 | | -increase_user_value $user '$U_CRON_JOBS' |
73 | | - |
74 | | -# Restart crond |
75 | | -$BIN/v-restart-cron "$EVENT" |
76 | | - |
77 | | -# Logging |
78 | | -log_history "added cron job $job" |
79 | | -log_event "$OK" "$EVENT" |
80 | | - |
81 | | -exit |
| 1 | +#!/bin/bash |
| 2 | +# info: add cron job |
| 3 | +# options: USER MIN HOUR DAY MONTH WDAY COMMAND [JOB] |
| 4 | +# |
| 5 | +# The function adds a job to cron daemon. When executing commands, any output |
| 6 | +# is mailed to user's email if parameter REPORTS is set to 'yes'. |
| 7 | + |
| 8 | + |
| 9 | +#----------------------------------------------------------# |
| 10 | +# Variable&Function # |
| 11 | +#----------------------------------------------------------# |
| 12 | + |
| 13 | +# Argument defenition |
| 14 | +user=$1 |
| 15 | +min=$2 |
| 16 | +hour=$3 |
| 17 | +day=$4 |
| 18 | +month=$5 |
| 19 | +wday=$6 |
| 20 | +command=$(echo $7 | sed -e "s/'/%quote%/g") |
| 21 | +job=$8 |
| 22 | + |
| 23 | +# Includes |
| 24 | +source $VESTA/conf/vesta.conf |
| 25 | +source $VESTA/func/main.sh |
| 26 | + |
| 27 | +# Assing new value |
| 28 | +A7="$command" |
| 29 | + |
| 30 | + |
| 31 | +#----------------------------------------------------------# |
| 32 | +# Verifications # |
| 33 | +#----------------------------------------------------------# |
| 34 | + |
| 35 | +check_args '7' "$#" 'USER MIN HOUR DAY MONTH WDAY COMMAND [JOB]' |
| 36 | +validate_format 'user' 'min' 'hour' 'day' 'month' 'wday' 'command' |
| 37 | +is_system_enabled $CRON_SYSTEM |
| 38 | +is_object_valid 'user' 'USER' "$user" |
| 39 | +is_object_unsuspended 'user' 'USER' "$user" |
| 40 | +is_package_full 'CRON_JOBS' |
| 41 | +get_next_cronjob |
| 42 | +validate_format 'job' |
| 43 | +is_object_free 'cron' 'JOB' "$job" |
| 44 | + |
| 45 | + |
| 46 | +#----------------------------------------------------------# |
| 47 | +# Action # |
| 48 | +#----------------------------------------------------------# |
| 49 | + |
| 50 | +# Concatenating cron string |
| 51 | +str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'" |
| 52 | +str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'" |
| 53 | + |
| 54 | +# Adding to crontab |
| 55 | +echo "$str" >> $VESTA/data/users/$user/cron.conf |
| 56 | + |
| 57 | +# Chaning permissions |
| 58 | +chmod 660 $VESTA/data/users/$user/cron.conf |
| 59 | + |
| 60 | +# Sort jobs by id number |
| 61 | +sort_cron_jobs |
| 62 | + |
| 63 | +# Sync cronjobs with system crond |
| 64 | +sync_cron_jobs |
| 65 | + |
| 66 | + |
| 67 | +#----------------------------------------------------------# |
| 68 | +# Vesta # |
| 69 | +#----------------------------------------------------------# |
| 70 | + |
| 71 | +# Increasing cron value |
| 72 | +increase_user_value $user '$U_CRON_JOBS' |
| 73 | + |
| 74 | +# Restart crond |
| 75 | +$BIN/v-restart-cron "$EVENT" |
| 76 | + |
| 77 | +# Logging |
| 78 | +log_history "added cron job $job" |
| 79 | +log_event "$OK" "$EVENT" |
| 80 | + |
| 81 | +exit |
0 commit comments