For grep expressions the OR operator is “\|“. Here is an example using tail on a file looking for 2 strings occurrences:
tail -f /var/log/apache2/error.log | grep "PHP Notice\|client denied"
or another example to list the content of the php.ini file without comments and empty lines:
grep -v "^#\|^$\|^;" /etc/php5/apache2/php.ini
Tags: grep, tips
The % character is a special char for crontab entries, and in order to use it we have to escape it. For example a crontab entry like this:
1 0 * * * /bin/sleep `/usr/bin/expr $RANDOM % 600` ; /usr/local/bin/mycommand
that attempts to run mycommand hourly with a random delay for the start, will fail because cron will see the % character and ignore the rest of the command; it will just run: /bin/sleep `/usr/bin/expr $RANDOM that will return a random number between 0-32767 and exit.
Read the rest of this entry »
Tags: cron, tips, Tips & Tricks
If you want to run fsck on a loopback filesystem (normally a virtual machine disk image like xen for ex.) you just have to tell its proper filesystem type when you run fsck:
fsck.ext3 /path/to/loopbackfile.ext3for ext3 or:
fsck.reiserfs /path/to/loopbackfile.reiserfsfor reiserfs, etc.
Tags: tips
Here is a quick tip that will show how you can tell your Linux system to perform a fsck on its partitions on the next reboot. Normally this will happen by default, after some time as configured in the filesystem at creation time (or changed later): after a number of days or a number of filesystem mounts. If you are using ext3 filesystems you can check these intervals configured with:
tune2fs -l <device>
...
Mount count: 5
Maximum mount count: 37
...
Last checked: Sat May 17 16:39:18 2008
Check interval: 15552000 (6 months)
Next check after: Thu Nov 13 15:39:18 2008
Read the rest of this entry »
Tags: tips
Running the latest version of ldapscripts from Debian lenny (ver 1.7.1-2) I was getting this error:
trap: usage: trap [-lp] [arg signal_spec ...]whenever I was running ldapadduser.
To fix this you have to edit /usr/share/ldapscripts/runtime and find the line:
...
# Reset traps
trap -
...
and change it to:
trap - 2in order to fix the trap error.
Tags: ldap, tips
After performing some security related OS updates, i was receiving from LDAP all sort of strange errors. Like, when you logged on the ldap server as a regular ldap user (not system user) the regular user@host:~$ prompt changed to:
I have no name!@host:~$
Read the rest of this entry »
Tags: ldap, tips
According to tune2fs manual, reserved blocks are designed to keep your system from failing when you run out of space. Its reserves space for privileged processes such as daemons (like syslogd, for ex.) and other root level processes; also the reserved space can prevent the filesystem from fragmenting as it fills up. By default this is 5% regardless of the size of the partition.
On large partitions (250GB drives and up are quite common these days), the default 5% reserved space can be quite a lot (12.5Gb in my example). For ext3 partitions you can tune this parameter by using tune2fs with the parameter -m. For ex. to decrease this to 3% you would run (for ex. on /dev/sda1):
tune2fs -m3 /dev/sda1
You should be very careful when ‘playing’ with this parameter and be sure you know what you are doing before changing this value. 
Tags: tips
This document describes how to install and use sshfs, a FUSE based filesystem that uses SSH to mount remote folders. Since it is based on FUSE (userspace filesystem framework for Linux) your kernel will need to have the fuse module available. FUSE is included in kernel newer than 2.6.14, so I will assume that you will have it already included in your kernel.
Read the rest of this entry »
Tags: fuse, ssh, sshfs, tips
Normally MySQL replication will stop whenever there is an error running a query on the slave. This happens in order for us to be able to identify the problem and fix it, and keep the data consistent with the mater that has sent the query. You can skip such errors, even if this is not recommended, as long as you know really well what are those queries and why they are failing, etc.
For example you can skip just one query that is hanging the slave using:
mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;
There might be cases where you will want to skip more queries. For example you might want to skip all duplicate errors you might be getting (output from show slave status;):
"1062 | Error 'Duplicate entry 'xyz' for key 1' on query. Default database: 'db'. Query: 'INSERT INTO ..."
Read the rest of this entry »
Tags: mysql, tips
The Unix find command is a very powerful tool, and this short post is intended to show how easy you can achieve something that might look complicate: to find all the files of a particular size. Let’s assume you are searching for all the files of exactly 6579 bytes size inside the home directory. You will just have to run something like:
find /home/ -type f -size 6579c -exec ls {} \;
As units you can use:
- b – for 512-byte blocks (this is the default if no suffix is used)
- c – for bytes
- w – for two-byte words
- k – for Kilobytes (units of 1024 bytes)
- M – for Megabytes (units of 1048576 bytes)
- G – for Gigabytes (units of 1073741824 bytes)
Read the rest of this entry »
Tags: tips