| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #!/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/cron.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
|