v_add_sys_cron 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # info: adding cron job
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user=$1
  8. min=$2
  9. hour=$3
  10. day=$4
  11. month=$5
  12. wday=$6
  13. command=$7
  14. job=$8
  15. # Importing variables
  16. source $VESTA/conf/vars.conf
  17. source $V_CONF/vesta.conf
  18. source $V_FUNC/shared.func
  19. source $V_FUNC/cron.func
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. # Checking arg number
  24. check_args '7' "$#" 'user min hour day month wday command [job]'
  25. # Checking argument format
  26. format_validation 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
  27. # Checking cron system
  28. is_system_enabled 'cron'
  29. # Checking user
  30. is_user_valid
  31. # Get str position
  32. if [ -z "$job" ]; then
  33. job=$(get_next_cron_string)
  34. fi
  35. # Checking id format
  36. format_validation 'job'
  37. # Checking job id
  38. is_cron_job_free
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Concatenating cron string
  43. command=$(echo $command|sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
  44. v_str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month"
  45. v_str="$v_str' WDAY='$wday' CMD='$command' SUSPEND='no' DATE='$V_DATE'"
  46. # Adding to crontab
  47. echo "$v_str">>$V_USERS/$user/cron.conf
  48. # Sorting jobs by id
  49. sort_cron_jobs
  50. # Sync system cron with user
  51. sync_cron_jobs
  52. #----------------------------------------------------------#
  53. # Vesta #
  54. #----------------------------------------------------------#
  55. # Adding task to the vesta pipe
  56. restart_schedule 'cron'
  57. # Logging
  58. log_history "$V_EVENT" "v_del_sys_cron $user $job"
  59. log_event 'system' "$V_EVENT"
  60. exit