1
0
mirror of https://github.com/serghey-rodin/vesta.git synced 2025-03-12 04:36:25 -07:00
vesta/bin/v-change-cron-job

81 lines
2.1 KiB
Plaintext
Raw Normal View History

2013-01-19 23:07:26 +02:00
#!/bin/bash
# info: change cron job
# options: USER JOB MIN HOUR DAY MONTH WDAY COMMAND
#
# The function is used for changing existing job. It fully replace job
# parameters with new one but with same id.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
2015-11-06 17:38:58 +02:00
# Argument definition
2013-01-19 23:07:26 +02:00
user=$1
job=$2
min=$3
hour=$4
day=$5
month=$6
wday=$7
command=$8
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
2013-01-19 23:07:26 +02:00
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '7' "$#" 'USER JOB MIN HOUR DAY MONTH WDAY COMMAND'
is_format_valid 'user' 'job' 'min' 'hour' 'day' 'month' 'wday' 'command'
2013-05-29 13:16:09 +03:00
is_system_enabled "$CRON_SYSTEM" 'CRON_SYSTEM'
2013-01-19 23:07:26 +02:00
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'cron' 'JOB' "$job"
2015-01-11 20:31:40 +02:00
is_object_unsuspended 'cron' 'JOB' "$job"
2013-01-19 23:07:26 +02:00
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Generating timestamp
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
2013-01-19 23:07:26 +02:00
# Concatenating cron string
command=$(echo $command | sed -e "s/'/%quote%/g")
2013-01-19 23:07:26 +02:00
str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
str="$str CMD='$command' SUSPENDED='no' TIME='$time' DATE='$date'"
2013-01-19 23:07:26 +02:00
# Deleting old job
sed -i "/JOB='$job' /d" $USER_DATA/cron.conf
# Adding new
echo "$str" >> $USER_DATA/cron.conf
# Sorting jobs by id
sort_cron_jobs
# Sync system cron with user
sync_cron_jobs
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
2015-10-28 16:34:41 +02:00
# Restarting crond
2013-06-01 14:25:44 +03:00
$BIN/v-restart-cron
2015-10-28 16:34:41 +02:00
check_result $? "Cron restart failed" >/dev/null
2013-01-19 23:07:26 +02:00
# Logging
log_history "changed cron job $job"
log_event "$OK" "$ARGUMENTS"
2013-01-19 23:07:26 +02:00
exit