v_change_sys_cron_job 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # info: changing cron job
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. user="$1"
  8. job="$2"
  9. min="$3"
  10. hour="$4"
  11. day="$5"
  12. month="$6"
  13. wday="$7"
  14. command="$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 job min hour day month wday command'
  24. # Checking argument format
  25. format_validation 'user' 'job' 'min' 'hour' 'day' 'month' 'wday' 'command'
  26. # Checking cron system
  27. is_system_enabled 'cron'
  28. # Checking user
  29. is_user_valid
  30. # Checking user is active
  31. is_user_suspended
  32. # Checking cron job
  33. is_job_valid
  34. # Checking job is active
  35. # is_job_suspended
  36. #----------------------------------------------------------#
  37. # Action #
  38. #----------------------------------------------------------#
  39. # Concatenating cron string
  40. command=$(echo $command|sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
  41. v_str="JOB='$job' MIN='$min' HOUR='$hour' WDAY='$wday'"
  42. v_str="$v_str MONTH='$month' DAY='$day' CMD='$command' SUSPEND='no'"
  43. # Deleting job
  44. del_cron_job
  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"
  58. log_event 'system' "$V_EVENT"
  59. exit $OK