Register
It is currently Sat Sep 20, 2014 9:56 am

Bash script to look for updates


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Thu May 08, 2008 12:43 pm   

Joined: Thu May 08, 2008 12:13 pm
Posts: 3
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:
[root@localhost 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.
[root@localhost 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


Top
 Profile  
 PostPosted: Thu May 08, 2008 12:53 pm   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
pagl420 wrote:

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?


why not "apt-get install sudo" ?


Top
 Profile  
 PostPosted: Thu May 08, 2008 1:50 pm   

Joined: Thu May 08, 2008 12:13 pm
Posts: 3
myownshadow wrote:
pagl420 wrote:

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?


why not "apt-get install sudo" ?


I'm using PCLinuxOS and it is setup to use su instead of sudo. The problem is when i do su it asks me for a password and i don't want that. I just want it to execute it without the password so conky can use its output


Top
 Profile  
 PostPosted: Fri May 09, 2008 12:10 pm   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
for security reasons there is no way to use su without password (only root can).
but there is a way to do that. u can use ssh!
look at this, http://www.akadia.com/services/ssh_scp_ ... sword.html


Top
 Profile  
 PostPosted: Fri May 09, 2008 3:13 pm   

Joined: Thu May 08, 2008 12:13 pm
Posts: 3
myownshadow wrote:
for security reasons there is no way to use su without password (only root can).
but there is a way to do that. u can use ssh!
look at this, http://www.akadia.com/services/ssh_scp_ ... sword.html


I see, that gets a bit more complex considering i just want to be notified of updates. No big deal though, i just thought it'd be cool to have.

Thanks.


Top
 Profile  
 PostPosted: Thu May 15, 2008 11:10 am   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
pagl420 wrote:
Hello everyone,
Code:
#!/bin/bash

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



It doesn't really matter much, but I thought that I'd clarify that the [[ used in "if" is not part of the syntax, but a command itself. This will work fine:
Code:
if apt-get update 2>&1 | grep -qF 'Get'; then
  if apt-get –simulate dist-upgrade 2>&1 | grep -qF 'Inst'; then
    apt-get –simulate dist-upgrade
  fi
fi


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: adds666 and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP