Announcement

Collapse
No announcement yet.

Some Bash Questions

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    [QUOTE=james147;321416]this is why you should not answer questions at 5AM because you cannot sleep
    lol for some reason that's the time I tend to crack the last piece of some code for something!

    There was no real reason for using multiple lines except it makes it easier to read and debug. You can combine the pipes into one expression or split them out into more if you wanted. But at the time I figured that those steps would be handy to see if something went wrong. It makes no difference to the end result however. It is slightly less efficient splitting it up, but for this situation it is not going to make any noticeable difference (only if you are handling thousands of mirrors would you even start to be able to measure the overhead).

    Overall when you do not need high performance it is better to go with the more readable solution to make maintenance easier and you should never optimize before you have a working solution
    Thanks for the tip!


    I seem to have a small problem with the end result because of a modification to my sources.list just prior to executing this. Right before runnign the fastest mirror hack, as I call it, I need to add the backports repo to the sources.list, so I do:
    Code:
    cp -vv /etc/apt/sources.list /etc/apt/sources.list.bak
    sed -i 's/universe/universe multiverse/g' /etc/apt/sources.list
    echo 'deb http://archive.ubuntu.com/ubuntu lucid-backports main restricted universe' >> /etc/apt/sources.list
    then I run netselect and when it is done, I end up with a bad /etc/apt/sources.list like this:
    Code:
    deb http://mirror.netcologne.de/ubuntu/ lucid main restricted universe multiverse
    deb http://mirror.netcologne.de/ubuntu/ lucid-updates main restricted universe multiverse
    deb http://mirror.netcologne.de/ubuntu/ lucid-security main restricted universe multiverse
     http://mirror.netcologne.de/ubuntu/
    deb http://mirror.netcologne.de/ubuntu/ lucid-backports main restricted universe multiverse
    It seems that no matter what there is always an empty line on the end of /etc/apt/sources.list so when netselect is done, it tried to place a URL on that empty line. I assumed I could use sed or awk to strip the blank line prior to netselect. I can, but the result is still the same once netselect is done.
    Last edited by Xplorer4x4; Feb 04, 2013, 06:46 PM.
    OS: Kubuntu 12.10/Windows 8
    CPU: Intel Core i7 2600K
    Motherboard: Gigabyte GA-Z77X-UD5H
    Memory: 2x4GB Corsair Dominator
    Graphics Card: MSI R7770
    Monitor: Dell 2208WFP
    Mouse: Mionix NAOS 5000
    PSU: Corsair 520HX
    Case: Thermaltake Mozart TX
    Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
    Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

    Comment


      #17
      Try this awk line instead:

      Code:
      awk -v mirror="$MIRROR" '{ if ($2 != "") {$2 = mirror}; print }' /etc/apt/sources.list > /tmp/sources.list
      Though it could be improved further to look for a mirror in $2 rather then looking for not nothing.

      If the mirrors are always the same this will work better:


      Code:
      awk -v mirror="$MIRROR" '{ if ($2 == "http://archive.ubuntu.com/ubuntu") {$2 = mirror}; print }' /etc/apt/sources.list > /tmp/sources.list

      Comment

      Working...
      X