Guest User

Untitled

a guest
Jan 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #!/bin/sh
  2. user=''
  3. host=''
  4.  
  5. # Install dependencies
  6. if ! command -v go >/dev/null; then
  7. brew install go
  8. fi
  9.  
  10. if ! command -v cronv >/dev/null; then
  11. go get github.com/takumakanari/cronv/cronv
  12. go build -o ./cronv github.com/takumakanari/cronv/cronv
  13. mv ./cronv /usr/local/bin
  14. fi
  15.  
  16. # Generate crontabs and reports for each user on the host
  17. crontab_path="./crontab/${host}"
  18. mkdir -p "${crontab_path}"
  19.  
  20. report_path="./report/${host}"
  21. mkdir -p "${report_path}"
  22.  
  23. for host_user in $(ssh "${user}@${host}" 'cut -f1 -d: /etc/passwd'); do
  24. crontab_file="${crontab_path}/${host_user}.crontab"
  25.  
  26. ssh \
  27. "${user}@${host}" \
  28. "sudo crontab -u ${host_user} -l" \
  29. 1>"${crontab_file}"
  30.  
  31. if test ! -s "${crontab_file}"; then
  32. rm "${crontab_file}"
  33. else
  34. cronv \
  35. --duration 1d \
  36. --from-time '00:00' \
  37. --title "${host_user}@${host}" \
  38. --output "${report_path}/${host_user}.html" \
  39. < "$crontab_file"
  40. fi
  41. done
Add Comment
Please, Sign In to add comment