Reputation: 21
I am looking for a simple script that i can use in a bash file to check if there are any system updates available.
I started with
#!/bin/bash
clear
updates=$(apt list upgradeable)
if [-n ${updates} ]; then
echo "updates available"
else
echo "no updates!"
fi
However, the problem is that even if there is no updates, you still get a return of "Listing... Done"
Look forward to any help or advise.
Cheers, Darren
Upvotes: 0
Views: 2193
Reputation: 1229
You can use aptitude for that.
aptitude -q -F%p --disable-columns search "~U"
Upvotes: 0
Reputation: 42017
The obvious option is to get rid if the line starting with Listing
; apt
also gives a warning when the STDOUT is not a TTY, so you want to get rid of that line too:
updates=$(apt list upgradeable |& grep -Ev '^(Listing|WARNING)')
grep -Ev '^(Listing|WARNING)'
does the mentioned work.
Upvotes: 1