Guest User

Untitled

a guest
Dec 11th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. history | grep 'apt update'
  2.  
  3. HISTTIMEFORMAT="%d/%m/%y %T " history | grep 'apt update'
  4.  
  5. ls -l /var/cache/apt/pkgcache.bin | cut -d' ' -f6,7,8
  6.  
  7. stat /var/cache/apt/pkgcache.bin
  8.  
  9. function trimString()
  10. {
  11. local -r string="${1}"
  12.  
  13. sed -e 's/^ *//g' -e 's/ *$//g' <<< "${string}"
  14. }
  15.  
  16. function isEmptyString()
  17. {
  18. local -r string="${1}"
  19.  
  20. if [[ "$(trimString "${string}")" = '' ]]
  21. then
  22. echo 'true'
  23. else
  24. echo 'false'
  25. fi
  26. }
  27.  
  28. function info()
  29. {
  30. local -r message="${1}"
  31.  
  32. echo -e "33[1;36m${message}33[0m" 2>&1
  33. }
  34.  
  35. function getLastAptGetUpdate()
  36. {
  37. local aptDate="$(stat -c %Y '/var/cache/apt')"
  38. local nowDate="$(date +'%s')"
  39.  
  40. echo $((nowDate - aptDate))
  41. }
  42.  
  43. function runAptGetUpdate()
  44. {
  45. local updateInterval="${1}"
  46.  
  47. local lastAptGetUpdate="$(getLastAptGetUpdate)"
  48.  
  49. if [[ "$(isEmptyString "${updateInterval}")" = 'true' ]]
  50. then
  51. # Default To 24 hours
  52. updateInterval="$((24 * 60 * 60))"
  53. fi
  54.  
  55. if [[ "${lastAptGetUpdate}" -gt "${updateInterval}" ]]
  56. then
  57. info "apt-get update"
  58. apt-get update -m
  59. else
  60. local lastUpdate="$(date -u -d @"${lastAptGetUpdate}" +'%-Hh %-Mm %-Ss')"
  61.  
  62. info "nSkip apt-get update because its last run was '${lastUpdate}' ago"
  63. fi
  64. }
  65.  
  66. <root@ubuntu><~/ubuntu-cookbooks/libraries>
  67. # runAptGetUpdate
  68.  
  69. Skip apt-get update because its last run was '0h 37m 43s' ago
  70.  
  71. /var/log/apt/term.log
  72.  
  73. [ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -7)" ] && sudo apt-get update
  74.  
  75. xenial% 9: ./linuxpatchdate
  76. 2016-07-19 54
  77. 2017-02-24 363
  78. 2017-03-08 7
  79. 2017-03-09 2
Add Comment
Please, Sign In to add comment