vesta/bin/v_add_sys_cron
2011-06-14 00:22:25 +03:00

83 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# info: adding cron job
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user="$1"
min="$2"
hour="$3"
day="$4"
month="$5"
wday="$6"
command="$7"
job="$8"
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared_func.sh
source $V_FUNC/cron_func.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '7' "$#" 'user min hour day month wday command [job]'
# Checking argument format
format_validation 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
# Checking cron system
is_system_enabled 'cron'
# Checking user
is_user_valid
# Get str position
if [ -z "$job" ]; then
job=$(get_next_cron_string)
fi
# Checking id format
format_validation 'job'
# Checking job id
is_cron_job_free
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Concatenating cron string
command=$(echo $command|sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
v_str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month"
v_str="$v_str' WDAY='$wday' CMD='$command' SUSPEND='no' DATE='$V_DATE'"
# Adding to crontab
echo "$v_str">>$V_USERS/$user/crontab.conf
# Sorting jobs by id
sort_cron_jobs
# Sync system cron with user
sync_cron_jobs
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Adding task to the vesta pipe
restart_schedule 'cron'
# Logging
log_history "$V_EVENT" "v_del_sys_cron $user $job"
log_event 'system' "$V_EVENT"
exit $OK