Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. Check if my cronJob already exist
  2. Put my cronJob if it does not already exist
  3. or
  4. update my cronjob if one of the parameter of the command is different
  5.  
  6. if [[ $(crontab -l | egrep -v "^(#|$)" | grep -q 'something'; echo $?) == 1 ]]
  7. then
  8. echo $(crontab -l ; echo '* 1 * * * something') | crontab -
  9. fi
  10.  
  11. echo "* 1 * * * something" | crontab -
  12.  
  13. echo "* 1 * * * something" | ssh user@host "crontab -"
  14.  
  15. # on the machine itself
  16. echo "$(echo '* 1 * * * something' ; crontab -l)" | crontab -
  17. # via ssh
  18. echo "$(echo '* 1 * * * something' ; ssh user@host crontab -l)" | ssh user@host "crontab -"
  19.  
  20. echo '0 0 * * 0 webadmin /usr/local/bin/tidy_logfiles' > ~/webadmin.cron
  21. scp -p ~/webadmin.cron root@remote_host:/etc/cron.d/webadmin
  22.  
  23. ssh -q root@remote_host rm -f /etc/cron.d/webadmin
  24.  
  25. unset VISUAL
  26. EDITOR='update_crontab () {
  27. set -e
  28. new=$(mktemp)
  29. if <"$1" grep -v "^#" | grep -w do_stuff; then
  30. # Remove existing entries containing do_stuff
  31. grep -v -w do_stuff "$1" >"$new"
  32. else
  33. cp "$1" "$new"
  34. fi
  35. # Add the new entry
  36. echo "1 2 3 4 5 do_stuff --new-options" >>"$new"
  37. mv "$new" "$1"
  38. }
  39. update_crontab' crontab -e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement