SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-02-04 12:29:19

donpi
Member
From: In the middle of nowhere in EU
Registered: 2012-02-04
Posts: 30

How to update&clean the system

Hi everybody!

I usually run this script for updating and cleaning the system..
What do you think about? Would you add or remove something?

Here the code..

#!/bin/bash

apt-get update
apt-get dist-upgrade -y
apt-get upgrade -y
apt-get install -f
apt-get autoclean
apt-get autoremove -y
apt-get clean


dpkg --purge `COLUMNS=300 dpkg -l "*" | egrep "^rc" | cut -d" " -f3`

echo -n "# Remove old kernels "
dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get --dry-run remove
dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y remove

Thx in advance for any suggestion!

Offline

Help fund CrunchBang, donate to the project!

#2 2012-02-04 13:24:11

Vansgo
#! Die Hard
Registered: 2011-05-02
Posts: 1,580
Website

Re: How to update&clean the system

Hi smile and welcome to CB Land

I am installing/upgrading today - will be testing

Offline

#3 2012-02-04 14:51:51

donpi
Member
From: In the middle of nowhere in EU
Registered: 2012-02-04
Posts: 30

Re: How to update&clean the system

Hi Vansgo!
Thx for the welcome! big_smile

Let me know about the script's testing! wink

Offline

#4 2012-02-04 15:00:19

Vansgo
#! Die Hard
Registered: 2011-05-02
Posts: 1,580
Website

Re: How to update&clean the system

I ran some of these commands with the "cb-welcome" script

installing some jack audio updates and then running autoclean smile

Offline

#5 2012-03-10 21:00:41

boomclart
#! Member
Registered: 2011-11-17
Posts: 83

Re: How to update&clean the system

I ran this and get the following errors at the start

david@crunchbang:~$ update_and_clean 
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
E: Could not open lock file /var/cache/apt/archives/lock - open (13: Permission denied)
E: Unable to lock the download directory
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
E: Could not open lock file /var/cache/apt/archives/lock - open (13: Permission denied)
E: Unable to lock the download directory
dpkg: requested operation requires superuser privilege
# Remove old kernels [sudo] password for david: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-2.6-amd64 linux-headers-2.6-liquorix-amd64
  linux-headers-2.6.32-5-amd64 linux-headers-2.6.32-5-common
  linux-headers-2.6.36-2.dmz.5-liquorix-amd64 linux-image-2.6-amd64
  linux-image-2.6-liquorix-amd64 linux-image-2.6.32-5-amd64
  linux-image-2.6.36-2.dmz.5-liquorix-amd64 linux-kbuild-2.6.32
0 upgraded, 0 newly installed, 10 to remove and 107 not upgraded.
Remv linux-headers-2.6-amd64 [2.6.32+29]
Remv linux-headers-2.6-liquorix-amd64 [2.6.36-25]
Remv linux-headers-2.6.32-5-amd64 [2.6.32-41]
Remv linux-headers-2.6.32-5-common [2.6.32-41]
Remv linux-headers-2.6.36-2.dmz.5-liquorix-amd64 [2.6.36-25]
Remv linux-image-2.6-amd64 [2.6.39+35.1~bpo60+1]
Remv linux-image-2.6-liquorix-amd64 [2.6.36-25]
Remv linux-image-2.6.32-5-amd64 [2.6.32-38]
Remv linux-image-2.6.36-2.dmz.5-liquorix-amd64 [2.6.36-25]
Remv linux-kbuild-2.6.32 [2.6.32-1]
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-2.6-amd64 linux-headers-2.6-liquorix-amd64 linux-headers-2.6.32-5-amd64 linux-headers-2.6.32-5-common linux-headers-2.6.36-2.dmz.5-liquorix-amd64 linux-image-2.6-amd64 linux-image-2.6-liquorix-amd64
  linux-image-2.6.32-5-amd64 linux-image-2.6.36-2.dmz.5-liquorix-amd64 linux-kbuild-2.6.32
0 upgraded, 0 newly installed, 10 to remove and 107 not upgraded.
After this operation, 294 MB disk space will be freed.
(Reading database ... 131165 files and directories currently installed.)
Removing linux-headers-2.6-amd64 ...
Removing linux-headers-2.6-liquorix-amd64 ...
Removing linux-headers-2.6.32-5-amd64 ...
Removing linux-headers-2.6.32-5-common ...
Removing linux-headers-2.6.36-2.dmz.5-liquorix-amd64 ...
Removing linux-image-2.6-amd64 ...
Removing linux-image-2.6-liquorix-amd64 ...
Removing linux-image-2.6.32-5-amd64 ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/dkms 2.6.32-5-amd64 /boot/vmlinuz-2.6.32-5-amd64
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-5-amd64 /boot/vmlinuz-2.6.32-5-amd64
update-initramfs: Deleting /boot/initrd.img-2.6.32-5-amd64
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.32-5-amd64 /boot/vmlinuz-2.6.32-5-amd64
Generating grub.cfg ...
Found background image: desktop-grub.png
Found linux image: /boot/vmlinuz-2.6.39-bpo.2-amd64
Found initrd image: /boot/initrd.img-2.6.39-bpo.2-amd64
Found linux image: /boot/vmlinuz-2.6.36-2.dmz.5-liquorix-amd64
Found initrd image: /boot/initrd.img-2.6.36-2.dmz.5-liquorix-amd64
Found Windows 7 (loader) on /dev/sda1
done
Removing linux-image-2.6.36-2.dmz.5-liquorix-amd64 ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/dkms 2.6.36-2.dmz.5-liquorix-amd64 /boot/vmlinuz-2.6.36-2.dmz.5-liquorix-amd64
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.36-2.dmz.5-liquorix-amd64 /boot/vmlinuz-2.6.36-2.dmz.5-liquorix-amd64
update-initramfs: Deleting /boot/initrd.img-2.6.36-2.dmz.5-liquorix-amd64
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.36-2.dmz.5-liquorix-amd64 /boot/vmlinuz-2.6.36-2.dmz.5-liquorix-amd64
Generating grub.cfg ...
Found background image: desktop-grub.png
Found linux image: /boot/vmlinuz-2.6.39-bpo.2-amd64
Found initrd image: /boot/initrd.img-2.6.39-bpo.2-amd64
Found Windows 7 (loader) on /dev/sda1
done
The link /vmlinuz.old is a damaged link
Removing symbolic link vmlinuz.old 
 you may need to re-run your boot loader
The link /initrd.img.old is a damaged link
Removing symbolic link initrd.img.old 
 you may need to re-run your boot loader
Removing linux-kbuild-2.6.32 ...

Do I need to change something in the script or run it as

david@crunchbang:~$ sudo update_and_clean 

Offline

#6 2012-03-10 21:19:23

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: How to update&clean the system

^ you probably need sudo, yeah. whenever i see 'permission denied', i know it must be a rights-issue, and 9 out of 10 times i just need to use sudo.

Offline

#7 2012-03-11 04:58:13

barkbombardier
#! Member
Registered: 2011-09-07
Posts: 77

Re: How to update&clean the system

Workes for me,thanks a million...and hello!

Offline

#8 2012-03-15 12:32:31

kri5
#! Die Hard
From: L.G.C. UK
Registered: 2011-11-10
Posts: 568

Re: How to update&clean the system

I saved the script at:

 ~/bin/update_and_clean

but when i try to run the script from the terminal with the the following command:

sudo update_and_clean

all i get is the following message:

sudo: update_and_clean: command not found

Any idea why?


#! Waldorf - 64bit - Xfce

Offline

#9 2012-03-15 13:29:51

2ManyDogs
dv#!
From: elsewhere
Registered: 2011-11-22
Posts: 1,346

Re: How to update&clean the system

Is ~/bin in your PATH? wink


Be eggsalad to each other.

Offline

#10 2012-03-15 13:36:41

kri5
#! Die Hard
From: L.G.C. UK
Registered: 2011-11-10
Posts: 568

Re: How to update&clean the system

^ ~/bin or /home/kris/bin is in my path.  I can execute another script from rhowaldt OK, it appears to be this one only. sad


#! Waldorf - 64bit - Xfce

Offline

#11 2012-03-15 13:46:26

2ManyDogs
dv#!
From: elsewhere
Registered: 2011-11-22
Posts: 1,346

Re: How to update&clean the system

Is the script executable? Try this:

cd ~/bin
chmod +x update_and_clean
sudo ./update_and_clean

If that works then try running it from somewhere else.


Be eggsalad to each other.

Offline

#12 2012-03-15 13:50:45

kri5
#! Die Hard
From: L.G.C. UK
Registered: 2011-11-10
Posts: 568

Re: How to update&clean the system

^ That worked, it's going through the process now, hopefully my PC will still be working when it's finished. lol  I shall try running from else where after it's finished.


#! Waldorf - 64bit - Xfce

Offline

#13 2012-03-15 13:59:37

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 13,970

Re: How to update&clean the system

In general, it's not considered a good idea to write a script that has to be run with as a sudoer; it's better to prepend sudo to each line within the script (`sudo apt-get update` etc.) that needs sudoer privileges.

When you first attempted to run the script with `sudo update_and_clean`, were you by any chance *in /bin*?  For some reason, the PATH seems to have a blind spot to whatever your current directory is, even if it's explicitly declared as part of your PATH.  That could explain why the above command wouldn't work, while `sudo ./update_and_clean` did.

Offline

#14 2012-03-15 14:02:37

kri5
#! Die Hard
From: L.G.C. UK
Registered: 2011-11-10
Posts: 568

Re: How to update&clean the system

^ The script was located in ~/bin if that's what you mean.  When I tried to execute it and it failed via the terminal I was not at ~/bin


#! Waldorf - 64bit - Xfce

Offline

#15 2012-03-15 14:13:17

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 13,970

Re: How to update&clean the system

Offline

#16 2012-03-15 14:20:34

kri5
#! Die Hard
From: L.G.C. UK
Registered: 2011-11-10
Posts: 568

Re: How to update&clean the system

@pvsage.. You are indeed a genius, adding 'sudo' to the lines in the script instead of trying to execute the script with 'sudo' did the trick, it now appears to work fine.  big_smile


#! Waldorf - 64bit - Xfce

Offline

#17 2012-07-27 06:17:18

yello
Member
From: France
Registered: 2008-12-14
Posts: 36

Re: How to update&clean the system

Many thanks donpi, works like a charm!

I was only looking to remove old kernels but this script automates all the stuff I do manually too, so it's a double bonus! big_smile

Offline

#18 2012-07-27 06:41:26

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: How to update&clean the system


I'm so meta, even this acronym

Offline

#19 2012-07-27 07:10:37

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 13,970

Re: How to update&clean the system

or better, `sudo -i;myscript;exit`

...or `su;myscript;exit`

Last edited by pvsage (2012-07-27 07:11:40)

Offline

#20 2012-07-27 11:44:02

dkeg
#! Die Hard
From: Mid-Atlantic Grill
Registered: 2011-12-05
Posts: 727

Re: How to update&clean the system

david@crunchbang:~$ update_and_clean 
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
.....

Offline

#21 2012-07-27 11:59:21

skbierm
#! Member
From: Germany
Registered: 2012-07-17
Posts: 89

Re: How to update&clean the system

Offline

#22 2012-07-27 12:00:07

GamBit
#! CrunchBanger
From: Vienna/Austria
Registered: 2012-07-22
Posts: 104

Re: How to update&clean the system

Welcome!

Nice script. I will test it.

Offline

#23 2012-07-27 19:33:55

talles
Member
Registered: 2012-07-11
Posts: 31

Re: How to update&clean the system

What apt-get clean and autoclean does?

I've always seen it, I have tried. I see no difference (I'm using only autoremove nowadays).

Whats the -y option with autoremove and dist-upgrade?

Offline

#24 2012-07-27 19:36:02

hinto
#! Windbag
From: Cary, NC
Registered: 2010-12-08
Posts: 1,487

Re: How to update&clean the system

Offline

Help fund CrunchBang, donate to the project!

#25 2012-07-27 19:59:47

pidsley
Window Mangler
Registered: 2012-05-23
Posts: 1,752

Re: How to update&clean the system

Last edited by pidsley (2012-07-27 20:04:29)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo