an Ubuntu sources.list with more whistles and bells
I’ve been fiddling around with my sources list, trying to make everything perfect before I sit down to get to work. But I found out that a fellow named Ketil, from Oslo, has limited my procrastination by doing a better job with a consolidated list. His /etc/apt/sources.list is here: http://anotherugly.wordpress.com/my-ubuntu-9-10-karmic-koala-sources-list/
linux/Unix tools for multiline grep
grep -A 2 SearchString
grep -B 3 SearchString
also,
pcregrep
pcregrep -M ‘a\nb’ files…
How to keep apache from autostarting on system boot for Debian or Ubuntu
An easy way to remove apache2 (or another system service) from the start up scripts in Debian or Ubuntu is to use the update-rc.d mechanism.
For instance:
# update-rc.d -f apache2 remove
The “-f” is required if you have existing scripts in /etc/init.d/apache2. If you are planning on manually starting apache, the “-f” is [barring heroic/quixotic effort to create alternatives] a requirement.
Otherwise, in this situation, you will see:
update-rc.d: /etc/init.d/apache2 exists during rc.d purge (use -f to force)
A good write-up is here:
http://www.debuntu.org/how-to-manage-services-with-update-rc.d
Ubuntu 9.10 (Karmic) Beta
Instead of ‘ do-release-upgrade ‘ as I did with my upgrade to 9.04 , going to the Beta of 9.10 I used
update-manager -d
No major problems. I did have to manually remove a couple of ppa entries from my /etc/apt/sources.list. Also, I changed from the generic ‘main server’ to a much, much faster (at the time) server. The easiest way to do this is via gui, as far as I know. Ubuntu will check for the fastest responding site if you use ‘System’ -> ‘Administration’ -> ‘Software Sources’ and ‘Select Best Server’,’ or use ‘Settings’ under the update-manager interface (‘settings’ is on the lower left) to get to the same place. I shaved off several hours from my package download by switching to a server that had some combination of proximity, light load, and high bandwidth. This involved a generous amount of luck, and probably the uneven demand associated with a pre-release version of the OS.
crontab editor (alternatives redux)
Well, my Debian server seems to think I should edit crontabs by with pico. So, the fix (as with Ubuntu) :
update-alternatives --set editor /usr/bin/vim.tiny
Is there a difference between “apt-get purge” vs. “apt-get remove –purge” ?
I was wondering this myself, as the two seemed to do the same thing. Google helpfully turned up a thread from ubuntu-users (Jan. ’09).
This post sums it up well (and accurately, I believe):
>Derek B. writes: >>Tommy T. wrote: >>> On Fri, Jan 23 [...] Pierre F. wrote:>>> hi,
>>> Is there any subtle difference between the 2 syntaxes?
>>> (I couldn’t find the answer in any documentation)
>>
>> Don’t they do different things?
>
>No.
un-ubuntuing visudo: how to make visudo use vi instead of nano
At some point, Ubuntu decided that it was best to have “visudo” — which refers to the vi editor by name — use the nano editor by default. If, like me, you are trying to edit the sudoers file, and you don’t want to use nano, or if you want to change visudo “back” to using vi (as intended), then read on. Note that this also will change your default editor to vi, or change the default to whatever editor you choose.
visudo takes its cue from the alternatives configuration system, which means it looks to /usr/bin/editor, which itself points to /etc/alternatives/editor.
The Ubuntu way to change the default editor (which will be used by visudo) then is to run
update-alternatives --config editor
That should go something like this:
laptop:~$ sudo update-alternatives --config editor
[sudo] password for obelix:
There are 6 alternatives which provide `editor'.
Selection Alternative
----------------------------------------------- 1 /usr/bin/vim.tiny
2 /bin/ed
3 /bin/nano
4 /usr/bin/vim.basic
*+ 5 /usr/bin/vim.gnome 6 /usr/bin/mcedit-debian
Press enter to keep the default[*], or type selection number: 1
Using '/usr/bin/vim.tiny' to provide 'editor'.
laptop:~$
Finally, here's what the filesystem structure looks like:
laptop:~$ ls -l /usr/bin/editor
lrwxrwxrwx 1 root root 24 2008-12-17 14:57 /usr/bin/editor -> /etc/alternatives/editor
laptop:~$ ls -l /etc/alternatives/editor
lrwxrwxrwx 1 root root 18 2009-04-23 17:32 /etc/alternatives/editor -> /usr/bin/vim.tiny
[sudo] password for :
There are 6 alternatives which provide `editor'.
Selection Alternative
-----------------------------------------------
1 /usr/bin/vim.tiny
2 /bin/ed
3 /bin/nano
4 /usr/bin/vim.basic
*+ 5 /usr/bin/vim.gnome
6 /usr/bin/mcedit-debian
Press enter to keep the default[*], or type selection number: 1
Using '/usr/bin/vim.tiny' to provide 'editor'.
laptop:~$
Fixing broken mysql / mysql-server under Ubuntu 9.04 (Jaunty) after a purge
I broke my server attempting to do some clean-up before making bigger changes. mysql would not restart, and the culprit was something like ‘apt-get purge mysql-server,’ which deleted the /etc/mysql directory . Various installs brought back /etc/mysql but without solving the problem:
% sudo apt-get install mysql-server mysql-common
Setting up mysql-server-5.0 (…)
* Stopping MySQL database server mysqld [ OK ]
* Starting MySQL database server mysqld [fail]
invoke-rc.d: initscript mysql, action “start” failed.
dpkg: error processing mysql-server-5.0 (–configure):
subprocess post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.0; however:
Package mysql-server-5.0 is not configured yet.
dpkg: error processing mysql-server (–configure):
dependency problems – leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
mysql-server-5.0
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
/var/log/dpkg:
2009-06-12 17:23:31 status half-installed mysql-server 5.1.30really5.0.75-0ubuntu10.2
In any case, the only way I could get things back running was to copy over the /etc/mysql directory from a working server, doing
% sudo apt-get remove –purge mysql-server
% sudo apt-get install mysql-server
and rebooting.
Here’s what the /etc/mysql directory looked like after the copy:
/etc/mysql# ls -l
total 16
drwxr-xr-x 2 root root 4096 2009-06-12 17:23 conf.d
-rw------- 1 root root 312 2009-06-12 17:23 debian.cnf
-rwxr-xr-x 1 root root 1198 2009-05-14 05:39 debian-start
-rw-r--r-- 1 root root 4088 2009-03-30 15:18 my.cnf
/etc/mysql# ls -l conf.d/
total 0
So, the copy provided the conf.d directory and the my.cnf file that the re-install failed to (re)create.
I’ve uploaded a copy of the default Ubuntu 9.04 /etc/mysql/my.cnf file here.
And here’s just the active info from my.cnf file
(filtered through egrep -v '^$|^#' my.cnf to remove empty lines and comment lines) :
—–start my.cnf——
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
bind-address = 127.0.0.1
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 128K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
expire_logs_days = 10
max_binlog_size = 100M
skip-federated
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
[isamchk]
key_buffer = 16M
!includedir /etc/mysql/conf.d/
—–end my.cnf——
Recreating that file may help you get mysql back running, as it appears to have been essential for me.
Incidentally, here is a handy search for printing which logfiles have info about your misbehaving program (in this case, mysql):
/var/log# egrep mysql * | awk -F: '{print $1}' | uniq
unix/linux redirection: empty files without typing /dev/null
Subtitled, Figurative and Literal Redirection, a post in which I alter my approach to redirection with explict shell redirection indicators.
When I started working with Unix, I generally used ”cat /dev/null’ to empty a file quickly and cleanly, e.g.,:
foozbear% cat /dev/null > big_useless_log
foozbear% cat /dev/null > /var/mail/mymail
This, of course, made big_useless_log or mymail empty (zero length), and did so without getting rid of it, in case a data write was imminent.
This week I was using a lot of temp files — actually using the same temp file over and over to hold data I’d scraped from Cisco switch output so I could point some ‘awk’ at it for parsing purposes (or, vice versa, really). For some reason, I decided to see what would happen if instead of removing and recreating the file (or more laboriously, typing cat /dev/null > temp), I used a redirection symbol, i.e.,
foozbear% > temp
Well, this worked as well as my previous steps, so I started alternating (using the command line up arrow) between my temp file resetting/editing
foozbear% > temp && vi temp
and my grep/awk line:
foozbear% egrep 'Gig|Fas' temp | awk '{print "interface "$2" "$3"n description "$1}'
This worked fantastically (note that I was using bash under Ubuntu here), and a good time was had by all (the Cisco switches were particularly pleased, having their cdp output turned into port descriptions so handily — but perhaps I’ll expand on that later).
The redirection symbol also can be used if you are too lazy to create an empty file using ‘touch’. Instead of
foozbear% touch newfile
just type
foozbear% > newfile
and you’re all set.
redirecting standard error (stderr) and standard output (stdout) to a file
Capturing both errors and normal list output from ls, with “long” and recursive options set, to a file called /tmp/allout :
ls -lR > /tmp/allout 2>&1