cron 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/base"
  3. # Add rvm variables on the beginning of crontab
  4. __rvm_cron_setup()
  5. {
  6. {
  7. echo "#sm start rvm"
  8. __rvm_env_print --cron
  9. echo "#sm end rvm"
  10. __sm.cron.show | __sm.filter.remove.group "^#sm start rvm$" "^#sm end rvm$"
  11. } | crontab -
  12. }
  13. __rvm_cron_remove()
  14. {
  15. __sm.cron.show | __sm.filter.remove.group "^#sm start rvm$" "^#sm end rvm$" | crontab -
  16. }
  17. __rvm_cron_command()
  18. {
  19. \typeset v schedule
  20. schedule="$1"
  21. shift || {
  22. rvm_error "Schedule not given, example: rvm cron command \"@daily\" rake calculate:stats"
  23. rvm_info "Refer to \`man 5 crontab\` for format of the scheduling definition."
  24. exit 1
  25. }
  26. [[ -n "$1" ]] || {
  27. rvm_error "Command not given, example: rvm cron command \"@daily\" rake calculate:stats"
  28. exit 2
  29. }
  30. {
  31. __sm.cron.show
  32. printf "%b" "${schedule} $(__rvm_which rvm) in \"$PWD\" do"
  33. for v in "$@"
  34. do printf "%b" " \"$v\""
  35. done
  36. printf "\n"
  37. } | crontab -
  38. }
  39. __sm.cron.show()
  40. {
  41. EDITOR="\command \cat" crontab -e 2>/dev/null
  42. }
  43. __sm.filter.remove.group()
  44. {
  45. __rvm_awk 'BEGIN{in_group=0} /'"$1"'/ {in_group=1} in_group==0 {print} /'"$2"'/ {in_group=0}'
  46. }
  47. action="${1:-}"
  48. shift
  49. case "$action" in
  50. setup|remove|command)
  51. __rvm_cron_$action "$@"
  52. ;;
  53. help)
  54. rvm_help cron
  55. ;;
  56. *)
  57. rvm_error_help "Unknown subcommand '$action'" cron
  58. exit 1
  59. ;;
  60. esac