Apt-cacher-ng on ubuntu

0
Here’s a cool way to speed up apt-get update and software install in your environment.

On the server, download apt-cacher-ng:

sudo apt-get install apt-cacher-ng

edit /etc/apt-cacher-ng/acng.conf and change the BindAddress to:

0.0.0.0

Now restart the service:

/etc/init.d/apt-cacher-ng restart

On the clients:

create /etc/apt/apt.conf.d/03proxy and add:

Acquire::http { Proxy "http://serveriP:3142"; };

now run:

sudo apt-get update

Then browse to:

http://serverIP:3142/acng-report.html

You should see something like:

apt-cacher-ng report

Leave a Comment

apt-get force default configuration

0
Let’s say you’d like to run “apt-get update && apt-get upgrade” and want walk away. But, you would not want to come back to a screen pending user input on whether to use the old configuration (assuming you made changes to it) or the new file within the .deb package.

Here’s how to automate that response:

apt-get -o DPkg::options="--force-confdef" -o DPkg::options::="--force-confold" dist-upgrade

or add the following to /etc/apt/apt.conf.d/ (could be any filename)

DKpg::Options { "--force-confdef"; "--force-confold"; }
Leave a Comment

apt-get very bad state

0
Here’s how to remove a package that has turned into a nightmare.

Here’s the error:

dpkg: warning: overriding problem because –force enabled:
Package is in a very bad inconsistent state – you should
reinstall it before attempting a removal.
(Reading database … 50584 files and directories currently installed.)
Removing mcollective-plugins-facts-facter …
sed: -e expression #1, char 52: unknown option to `s’
dpkg: error processing mcollective-plugins-facts-facter (–remove):
subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
mcollective-plugins-facts-facter

here’s the fix that worked for me:

 cd /var/lib/dpkg/info 
 rm -rf mcollective-plugins-facts-facter.* 
 dpkg --remove --force-remove-reinstreq mcollective-plugins-facts-facter 

That’s it!

Leave a Comment

pdsh on ubuntu

0
pdsh is a nice tool to run commands in parallel on various machines. However, the package itself fails to work out of the box. So the following will result in an error:

 pdsh -w ptaylor@10.40.160.54 hostname 

* this command tries to connect to 10.40.160.54 and get the hostname

This would fail with:

 pdsh@ubuntu: 10.40.160.54: rcmd: socket: Permission denied 

Not very helpful.

Turns out it is looking for a file in /etc/pdsh:

 /etc/pdsh/rcmd_default 

I found this out by looking at /usr/bin/pdsh (bash script).

Once you’ve created the rcmd_dafault file, just add “ssh” to it.

 echo "ssh" | sudo tee -a /etc/pdsh/rcmd_default 

Now if you try running pdsh again, it should work just fine:

% pdsh -w ptaylor@10.40.160.54 hostname
10.40.160.54: ubuntuserver2
Leave a Comment

Apt-get update taking too long

1
Turns out if you have Google’s Chrome browser installed, apt-get update takes quite of a bit time getting headers.

I’ve seen this multiple times and I still keep forgetting to make the necessary changes prior to running:

 sudo apt-get update 

Here’s a fix I found that works for me (I’m using 12.04LTS).

 echo "Acquire::http::Pipeline-Depth "0";" | sudo tee -a /etc/apt/apt.conf.d/90localsettings 

The bug is known at:

 https://code.google.com/p/chromium/issues/detail?id=93409 
Leave a Comment

MySQL crashed tables

0
Check for crashed tables:

check all databases

 mysqlcheck -c -u root -p --all-databases 

check specific database table

 mysqlcheck -c <dbname> <tablename> -u root -p 

Repairing table

 mysqlcheck -r <dbname> <tablename> -u root -p 

Check, optimize and repair all the tables

 mysqlcheck -uroot -p --auto-repair -c -o --all-databases 
Leave a Comment

Rubygems zlib LoadError

0
Here’s how to fix the zlib error – At least this is what worked for me.

Here’s the error:

*** REMOTE GEMS ***
/home/ptaylor/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require’: cannot load such file — zlib (LoadError)

Here’s the fix:

 rvm pkg install zlib 
 rvm remove 1.9.3 
 rvm install 1.9.3 
Leave a Comment

Ruby find duplicates in Array

0
In python, I would usually use the collections.Counter module to read through an array and find duplicates. Here’s how to do the same thing in ruby.

# Let's say I have this array
a = %w[apple apple apple ubuntu ubuntu ubuntu ubuntu debian redhat]

def main(obj)
  # Set Hash to 0 so it counts
  counter = Hash.new(0)

  # iterate over the list
  obj.each { |x| counter[x] += 1 }

  # return the Hash
  return counter
end

# now run counters
puts main(a)

rubyduplicates

So now when you run the code, you’ll get an output like this:

run_duplicates

Leave a Comment

Ruby find methods that match a regex pattern

0
Here’s a quick way to query whether a Ruby Class has a certain method:

String.methods.grep(/^wr/)

or

String.methods.grep /^wr/

Everyone has their format.

So with the above, you can then say well since there’s no method that begins with “wr”, I can add one if I wanted.

class String
  def write_size
    self.size
  end
end

puts 'Hello'.write_size
Leave a Comment

Ubuntu Terminal Colors

0
I recently changed to zsh and kept wondering why my terminal colors weren’t aligned with what I had on my Mac. Turns out this is a simple fix:

 export TERM="xterm-256color" 

xterm_colors

You might need ncurses-term.

 sudo apt-get install ncurses-term 

You can also check that you have 256 colors available by running:

 tput colors 
Leave a Comment