Hello everyone,
I'm a complete newbie to bash scripting, and im trying to figure out how i can check for updates using apt-get commands and use it in conky system monitor. So far this is what i've found from a site.
Code:
#!/bin/bash
#
# Runs “apt-get update†and prints the output of a simulated
# dist-upgrade if new packages are found.
if [[ `apt-get update 2>&1 | grep Get` ]]; then
if [[ `apt-get –simulate dist-upgrade 2>&1 | grep Inst` ]]; then
apt-get –simulate dist-upgrade
fi
fi
From:
http://www.mattiaswikstrom.net/linux/20050526-apt-update-script.html)
The apt-get --simulate dist-upgrade returns the following:
Code:
[
[email protected] pagl420]# apt-get --simulate dist-upgrade
Reading Package Lists... Done
Building Dependency Tree... Done
Calculating Upgrade... Done
0 upgraded, 0 newly installed, 0 removed and 0 not upgraded.
[
[email protected] pagl420]#
The above code works, but the problem is i can do apt-get only as root. Is there any way to do su inside the script?
What i would like for it to to do is output is just "x updates available" read from "0 upgrade" in this line:
Code:
0 upgraded, 0 newly installed, 0 removed and 0 not upgraded.
or if no updates output "No updates available".
If anyone can write this script or suggest improvement to the above that would be greatly appreciated.
Thanks