v_change_sys_cron_job 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_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 job min hour day month wday command'
  25. # Checking argument format
  26. format_validation 'user' 'job' 'min' 'hour' 'day' 'month' 'wday' 'command'
  27. # Checking cron system
  28. is_system_enabled 'cron'
  29. # Checking user
  30. is_user_valid
  31. # Checking user is active
  32. is_user_suspended
  33. # Checking cron job
  34. is_job_valid
  35. # Checking job is active
  36. # is_job_suspended
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Concatenating cron string
  41. command=$(echo $command|sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
  42. v_str="JOB='$job' MIN='$min' HOUR='$hour' WDAY='$wday'"
  43. v_str="$v_str MONTH='$month' DAY='$day' CMD='$command' SUSPEND='no'"
  44. # Deleting job
  45. del_cron_job
  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"
  59. log_event 'system' "$V_EVENT"
  60. exit