Fedora/RedHat persistent multicast route  

I needed to add a persistent (after a reboot) route for multicast. I created a file called /etc/sysconfig/network-scripts/route-eth0 and put this in it:

224.0.0.0/4 dev eth0

This says route the entire multicast section of IPV4 through eth0. This ensures that your IGMP requests go out the appropriate port.

Leave A Reply

Remove files created more than 30 days ago  

I wanted to find all the files in a certain directory that were created more than 30 days ago. I started with:

find /path/to/dir -ctime +30

This was finding directories also, so I added -type

find /path/to/dir -ctime +30 -type f

This listed all the files I wanted, so I just passed -exec

find /path/to/dir -ctime +30 -type f -exec rm {} +

The {} in the -exec is replaced with the file names found, so all the files are removed.

Leave A Reply

Perl: Increment a number in a text file  

I have a manifest file that contains a build_version=XX number field (among a lot of others) that I want to automatically increment. I found a simple Perl one liner that searches a file and does a search and replace that can perform some math.

perl -pi -e 's/(build_version)=(\d+)/"build_version=" . ($2 + 1)/e' manifest

In this example the /e in the regexp says that the replace value is an expression. In this case the replace value is some math that add adds one to the current value.

Leave A Reply

Vim: Launch Vim with a predefined search string  

I wanted to launch Vim with a search string already set. That way I could load my file, and just hit N to jump to that location.

vim myfile.txt +/search_text

Whatever you set search_text to, will pre-fill the search buffer.

Leave A Reply

Setting and reading file xattrs  

If your filesystem supports xattrs you can set metadata to be saved with your files:

touch foo
setfattr -n user.fave_food -v hotdogs foo
getfattr -n user.fave_food foo

You must save everything in the user. namespace though.

Leave A Reply

Using rsync to backup files as a non-root user  

I'm using rsync over SSH to do backups between two systems. When you run your backup as non-root user, you cannot save the files owner or group (uid/gid) because only root is allowed to change ownership. You can however tell rsync to store the owner/group in the file's xattrs. This requires that you mount your filesystems with user_xattr:

/dev/sdb1 /backup ext4    defaults,user_xattr        1 2

Then you tell the writing rsync to use --fake-super

rsync -avP --rsync-path='/usr/bin/rsync --fake-super' /src/dir backup-user@domain.com:/dst/dir

This example is a push backup, if it were a pull you'd put --fake-super on the local side. Then to do a restore you'd do the same thing in reverse with the reading side (where the xattrs are stored) getting --fake-user:

rsync -avP --rsync-path='/usr/bin/rsync --fake-super' backup-user@domain.com:/src/dir /dst/dir

You can see the attributes for a given file with getfattr:

getfattr -d *

# file: dovecot.index
user.rsync.%stat="100600 0,0 89:89"

If you don't get any output, there are no xattrs for that file.

Leave A Reply

MySQL Complicated subquery joins  

We needed to do two complicated (group by/having) queries, and find the common CustIDs between them. Easy way is to create a temporary table with the CustIDs from the first table, and then do an INNER JOIN against that temporary table on the select for the second table.

DROP TABLE IF EXISTS CustID;
CREATE TEMPORARY TABLE CustID (CustID Integer);

INSERT INTO CustID (CustID)
   SELECT CustID
   FROM ViewCircuitServices
   WHERE SvcID = 3 AND CircuitType = 'dsl'
   GROUP BY CustID
   HAVING count(SvcID) >= 2;

SELECT CustID, SvcID
FROM ViewCircuitServices
INNER JOIN CustID USING (CustID)
WHERE SvcID IN (2,9,25) AND CircuitType = 'dsl'
GROUP BY CustID;
Leave A Reply

Enable background consistency check with arcconf  

To enable the (recommended) background consistency check on an Adaptec card run:

arcconf datascrub 1 period 30

Where 30 is the amount of days you want the adapter to scan the entire driveset.

Leave A Reply

Interfacing with Oracle on the command line  

I wanted a command line client to access an Oracle server. sqlplus64 is the stock Oracle client. Connect to your server with the following command:

sqlplus64 username/password@//1.2.3.4/database_name

If you want to see all the tables in the current DB:

select table_name from user_tables;

If you want to see the field names/types of a given table

desc tablename
Leave A Reply

Linux: Determine the type of memory in your machine  

I needed to find out what type of memory I had in a server, without shutting it down and opening the case.

dmidecode --type memory
Leave A Reply

Books of 2013  

Also see the list of 2012. The date indicated denotes the date I started reading the book.

2013-01-04 - Shards of Honor - 239 pages
2013-01-12 - Saga of the Swamp Thing - 208 pages
2013-01-14 - Bone Volume 1 - 142 pages
2013-01-16 - The Best of H.P. Lovecraft - 432 pages
2013-02-19 - Batman, officer down - 160 pages
2013-03-01 - The Last Policeman - 288 pages
2013-03-05 - Fear Itself: Uncanny X-Force/The Deep - 152 pages
2013-03-18 - Desperation - 690 pages
2013-04-01 - Left behind - 468 pages
2013-04-16 - Brief Encounter: An Erotic Short - 41 pages
2013-04-18 - On the Road - 320 pages

2013-05-09 - The Regulators - 466 pages
Leave A Reply

Vim encryption  

Vim has some simple built in encryption. If you have a text file you want to encrypt you can run the command:

:X

Vmi will prompt you for a password (twice). The next time you save the file it will encrypt the file before saving it. When you open the file it will prompt you for the password. If you enter the wrong password you'll see a bunch of gibberish.

Leave A Reply

Ignore SSH host key checking  

I have a range of IPs that I use for testing various Linux installations. This causes grief as each install gets its own SSH key. To tell SSH to ignore the key for a given IP address change your ~/.ssh/config

Host 192.168.0.*
    StrictHostKeyChecking no
    UserKnownHostsFile=/dev/null

Or if you just want to change it on a per connection basis at the command line:

ssh -o UserKnownHostsFile=/dev/null,StrictHostKeyChecking=no user@domain.com
Leave A Reply

Override the text selection (highlight) color with CSS  

If you want to override the default text selection or highlight color you can. Simple apply the ::selection selector in your CSS and change the color, font, or whatever you want.

::selection {
    background: #ffb7b7; /* Safari */
}

::-moz-selection {
    background: #ffb7b7; /* Firefox */
}
Leave A Reply

ffmpeg libx264 subtitle codec  

I tried to convert a mkv into a mp4 and while keeping the subtitles in tact. mp4 files require a different format of subtitles called mov_text.

ffmpeg -y -i input.mkv -c:v copy -c:a copy -c:s mov_text /tmp/output.mp4
Leave A Reply