Core Files Finder

I wrote this about a year ago, to find massive amounts of core files and email them back to me.

This is best ran in the background, as the outputs are nulled. I.E:

./corefinder &

Have fun!

#!/bin/bash
# Find's Core Files, and reports back

TMPDIR='/tmp'

subject="FindCores_Report_for_`hostname`"
EMAIL="[email protected]"
rm -f $TMPDIR/findcores.*
ls /var/cpanel/users/ > $TMPDIR/findcores.users
for i in `cat $TMPDIR/findcores.users`
	do
		if [ -e /home/$i ]; then
			#echo "Checking $i"
			echo "Report for $i" >> $TMPDIR/findcores.$i.corefiles
			cd /home/$i && find . -type f -regex '.*/core\.?[0-9]*$' >> $TMPDIR/findcores.$i.corefiles
			if [ `cat $TMPDIR/findcores.$i.corefiles | wc -l` -lt 25 ]; then
			#echo "Non-Alert"
			rm -f $TMPDIR/findcores.$i.corefiles
			else
			#echo "Alert"
			cat $TMPDIR/findcores.$i.corefiles | mail -s $subject $EMAIL
			fi
			rm -f $TMPDIR/findcores.$i.corefiles
		fi
done

MySQL Grants

Here’s a quick MySQL query that will setup grants for the specified user, on the specified database:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, CREATE ROUTINE ON `user\_database`.* TO 'user_username'@'%' IDENTIFIED by 'password';

SED New Line

Ever needed to use ‘sed’ to exchange new lines for another character? Here’s a way to do it:

sed ':a;N;$!ba;s/\n/ /g'

Inode One-Liner

Here’s a great one-liner for finding out how many inodes you have in a directory:

echo "Detailed Inode usage for: $(pwd)" ; for d in `find -maxdepth 1 -type d |cut -d\/ -f2 |grep -xv . |sort`; do  c=$(find $d |wc -l) ; printf "$c\t\t- $d\n" ; done ; printf "Total: \t\t$(find $(pwd) | wc -l)\n"