v_add_cron_job 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. # info: add cron job
  3. # options: user min hour day month wday command [job]
  4. #
  5. # The function adds a job to cron daemon. When executing commands, any output
  6. # is mailed to user's email if parameter REPORTS is set to 'yes'.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. user=$1
  12. min=$2
  13. hour=$3
  14. day=$4
  15. month=$5
  16. wday=$6
  17. command=$7
  18. job=$8
  19. # Includes
  20. source $VESTA/conf/vesta.conf
  21. source $VESTA/func/shared.sh
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '7' "$#" 'user min hour day month wday command [job]'
  26. validate_format 'user' 'min' 'hour' 'day' 'month' 'wday' 'command'
  27. is_system_enabled $CRON_SYSTEM
  28. is_object_valid 'user' 'USER' "$user"
  29. is_object_unsuspended 'user' 'USER' "$user"
  30. is_package_full 'CRON_JOBS'
  31. get_next_cronjob
  32. validate_format 'job'
  33. is_object_free 'cron' 'JOB' "$job"
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Concatenating cron string
  38. command=$(echo $command | sed -e "s/'/%quote%/g" -e "s/:/%dots%/g")
  39. str="JOB='$job' MIN='$min' HOUR='$hour' DAY='$day' MONTH='$month' WDAY='$wday'"
  40. str="$str CMD='$command' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
  41. # Adding to crontab
  42. echo "$str" >> $VESTA/data/users/$user/cron.conf
  43. # Chaning permissions
  44. chmod 660 $VESTA/data/users/$user/cron.conf
  45. # Sort jobs by id number
  46. sort_cron_jobs
  47. # Sync cronjobs with system crond
  48. sync_cron_jobs
  49. #----------------------------------------------------------#
  50. # Vesta #
  51. #----------------------------------------------------------#
  52. # Increasing cron value
  53. increase_user_value $user '$U_CRON_JOBS'
  54. # Restart crond
  55. $BIN/v_restart_cron "$EVENT"
  56. # Logging
  57. log_history "$EVENT"
  58. log_event "$OK" "$EVENT"
  59. exit