Peter Davies

Contact

E: Peter Davies
P: 0845 310 5320

SocNet's

Blog

Find specific text in files recursively

posted 25 Jan 2010 01:15 by Peter Davies

This is a simple one:

find ./ -type f -name '*.p*' -exec grep -s *115 {} \; -print

or to a file:

find ./ -type f -name '*.php' -exec grep -s VAT {} \; -print > ~/output.txt

Very useful though!

Clear/Flush Windows DNS cache

posted 12 Jan 2010 05:32 by Peter Davies

This would have been handy to know a few years ago:

ipconfig /flushdns

On Vista you need to run this as administrator (elevated permissions).

VMware time sync issues ntpd or not?

posted 22 Dec 2009 06:43 by Peter Davies   [ updated 12 Jan 2010 05:39 ]

Damn time sync on VMware has been a right pain - servers would increase their running time every few days by several minutes - very annoying for time-based execution of scripts.

In summary I just ran ntpd :- primarily from: http://en.gentoo-wiki.com/wiki/Time_Synchronization

emerge -p openntpd
/etc/init.d/ntpd start
rc-update add ntpd default


Job done.

exit signal File size limit exceeded

posted 9 Dec 2009 13:51 by Peter Davies

I recently ran into an error whilst trying to debug an application.
The actual error that appeared on screen was blank and a quick of the apache logs revealed multiple:

exit signal File size limit exceeded

I soon realised that the php_error_log had reached a 2Gb file limit meaning that it could no longer be written to.

echo "" > php_errors.log

Restart apache and then the system works again!

apt-get NO_PUBKEY / GPG error

posted 23 Nov 2009 01:33 by Peter Davies

This error occurs from time to time on some of our Debian boxes, extremely simple to fix just requires the process of obtaining the authenticity of the packages.

After running apt-get update you will see a series of keys that the system does not trust, simply make a note and substitute the key value in the following command:

gpg --keyserver pgpkeys.mit.edu --recv-key 841D6D8DFE3F8BB2
gpg -a --export 841D6D8DFE3F8BB2 | sudo apt-key add -


Now run apt-get update again and continue to update the installed packages as you would do normally:

apt-get update


One further note, we run several XenServer instances and spotted that we got the following error:

gpg: no valid OpenPGP data found.

The only solution we found was written by Steve Glendinning suggesting:

wget -q http://updates.vmd.citrix.com/XenServer/5.5.0/GPG-KEY -O- | apt-key add -

Which worked a treat and the apt-get update reported no faults.

rm: Argument list too long

posted 9 Sep 2009 02:22 by Peter Davies

Magento is odd... the session directory stores a lot of session files so much so I got a:

rm sess*
/bin/rm: Argument list too long.


So, that implies there's too many files to delete! The simplest alternative is to then use the following which deletes each file in-turn:

find . -name 'sess*' -print0 | xargs -0 rm

Gentoo distribution files cleanup

posted 7 Sep 2009 00:59 by Peter Davies

Here is a simple command set to clean up large distfiles directories:

eclean distfiles
eclean packages


Find and delete zero sized files

posted 18 Aug 2009 03:01 by Peter Davies

I recently had a "disk full" issue on a server but even after clearing out the apache logs that had failed to rotate the website that the server was running showed broken images where thumbnails should be.

After a little investigation it turned out the thumbnail code had tried to replace/create "zero" sized thumbnail images. The complication was that the images were spread across multiple directories meaning that it was going to be almost impossible to delete manually.

A combination of Google searches resulted in:

find ./ -type f -size 0 -exec rm {} \;

Very useful! And of course I backed up first!

Combine multiple text files

posted 18 Aug 2009 02:22 by Peter Davies   [ updated 18 Aug 2009 02:23 ]

This simple script joins multiple text files together allowing you to perform a single file DB import for example:

#!/bin/bash
for file in `ls ./*.txt`
do
    cat $file >> all.files
done


Find and replace in a large file

posted 28 May 2009 00:52 by Peter Davies   [ updated 4 Mar 2010 01:59 by Peter Davies ]

I have a 2Gb database dump that needed the database name changing (remember trailing slash):

cat sql_file | sed 's/olddbname/newdbname/'

and to check that it's complete:

grep olddbname sql_file

‹ Prev    1-10 of 42    Next ›