Scripts

Catching Apache segfaults due to eAccelerator

Last night we migrated our Linode for Gamers With Jobs to a new Xen VPS and we've noticed a significant performance boost. We did, however, start encountering a random issue with segmentation faults in Apache. If you haven't seen this happen before, it tends to begin innocently with one Apache process dying, and therefore giving errors (usually WSOD), but quickly balloons into dozens of dead processes. It essentially hoses Apache.

Apparently the issue is due to eAccelerator, so I reinstalled it and cleared its caches in the hope that it might limit its occurrence. Just in case, though, 2bits has a great fix for it, using the logwatcher script by Firebright, Inc. I was able to quickly get it going, and the only difference is that I used the Debian init.d script provided by Derek Laventure to run it.

Useful bash scripts

Just some personally useful bash scripts:

Find and delete files using a pattern

Find all files containing a particular string and do something with them - in this case, delete all files like "._*" i.e. "._user.module". This is usually junk left over from dead SSH sessions

for FILE in $(find . | grep '\._'); 
  do 
  rm $FILE; 
done;

Extract and import dumped SQL

This one comes from my work on gamerswithjobs.com, where I frequently received database dumps in the form of table dumps and need to decompress the import the SQL into a local DB. Also useful for bulk archiving or decompressing a large number of files.

echo "Extracting archives...";
for FILE in `ls *.gz`; 
  do 
  echo "Extracting $FILE ..."; 
  gzip -d $FILE; 
done;
 
echo "Importing SQL...";
for FILE in `ls *.sql`; 
  do 
  echo "Importing $FILE ..."; 
  mysql -h dbhost -u dbuser -pdbpass dbname < $FILE; 
done;

Dump and compress database tables

Another useful one from gamerswithjobs.com work. This one dump each table from a database as an individual .sql file. This is particularly useful for extremely large databases where a straight dump of the entire DB would take longer than acceptable, either by potential crashes or by sys admin enforcement of a max execution time of commands.

echo "Dumping tables...";
for TBL in `mysql -e "show tables" -N -h dbhost -u dbuser -pdbpass dbname`;
  do 
  echo "Dumping $TBL";
  mysqldump -h dbhost -u dbuser -pdbpass dbname $TBL > $TBL.sql;
done;
 
echo "Compressing dumped tables...";
for FILE in `ls *.sql`; 
  do 
  echo "Compressing $FILE ..."; 
  gzip $FILE; 
done;

Syndicate content