check-package-up2date.sh 503B

12345678910111213141516171819
  1. #!/bin/bash
  2. #Based on http://unix.stackexchange.com/questions/175146/apt-get-update-exit-status
  3. #And http://unix.stackexchange.com/questions/19470/list-available-updates-but-do-not-install-them
  4. if ! { apt-get update 2>&1 || echo E: update failed ;} | grep -q '^[WE]:';then
  5. echo update success
  6. else
  7. echo update failure
  8. exit 1
  9. fi
  10. if [ $(aptitude search '~U' | wc -l) -gt 0 ];then
  11. echo Need-to-update
  12. exit 1
  13. else
  14. echo No-Need-to-update
  15. exit 0
  16. fi