v_add_sys_cron 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_FUNC/shared_func.sh
  18. source $V_FUNC/cron_func.sh
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. # Checking arg number
  23. check_args '7' "$#" 'user min hour day month wday command [job]'
  24. # Checking argument format
  25. format_validation 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
  26. # Checking cron system
  27. is_system_enabled 'cron'
  28. # Checking user
  29. is_user_valid
  30. # Get str position
  31. if [ -z "$job" ]; then
  32. job=$(get_next_cron_string)
  33. fi
  34. # Checking id format
  35. format_validation 'job'
  36. # Checking job id
  37. is_cron_job_free
  38. #----------------------------------------------------------#
  39. # Action #
  40. #----------------------------------------------------------#
  41. # Concatenating cron string
  42. command=$(echo $command|sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
  43. v_str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month"
  44. v_str="$v_str' WDAY='$wday' CMD='$command' SUSPEND='no' DATE='$V_DATE'"
  45. # Adding to crontab
  46. echo "$v_str">>$V_USERS/$user/crontab.conf
  47. # Sorting jobs by id
  48. sort_cron_jobs
  49. # Sync system cron with user
  50. sync_cron_jobs
  51. #----------------------------------------------------------#
  52. # Vesta #
  53. #----------------------------------------------------------#
  54. # Adding task to the vesta pipe
  55. restart_schedule 'cron'
  56. # Logging
  57. log_history "$V_EVENT" "v_del_sys_cron $user $job"
  58. log_event 'system' "$V_EVENT"
  59. exit $OK