Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Rip an Icecast stream

Rip an Icecast stream (for a 30 min duration), and direct the streamripper text including errors to /dev/null. Note: Directing the output to null is necessary when running this within a cron job.

streamripper http://192.168.1.7:8000/radio_x.ogg.m3u -dq  ~james/Streamripper_rips/hay -a %d -l 1800 >/dev/null 2>&1

truncate Rails development/test logs

In rails applications development.log and test.log like to grow forever, which takes up space and makes them slow to grep. If I just delete them running processes with logs open might get confused. So I can use truncate instead:

truncate ~/www/*/log/*.log


Even easier, ask cron to do it for me every night:
4 22 * * * * truncate -s 0k  ~/www/*/log/*.log

Simple mySQL backup script for cron

Simple mySQL backup script for cron - backs up all databases, saves the last 4 copies.
#!/bin/bash

# modify the following to suit your environment
export DB_BACKUP="/backup/mysql_backup"
export DB_USER="root"
export DB_PASSWD="********"

# title and version
echo ""
echo "mySQL_backup"
echo "----------------------"
echo "* Rotating backups..."
rm -rf $DB_BACKUP/04
mv $DB_BACKUP/03 $DB_BACKUP/04
mv $DB_BACKUP/02 $DB_BACKUP/03
mv $DB_BACKUP/01 $DB_BACKUP/02
mkdir $DB_BACKUP/01 

echo "* Creating new backup..."
mysqldump --user=$DB_USER --password=$DB_PASSWD --all-databases | bzip2 > $DB_BACKUP/01/mysql-`date +%Y-%m-%d`.bz2
echo "----------------------"
echo "Done"
exit 0

Backup MySQL databases into seperate files

A cronable script for backing up all your databases as seperate files. I'd suggest limiting the backup user's access to the IP of the computer backing up, and using some sort of encryption if you're on a capable version of mysql.

#!/bin/sh
#
# MySQL backups from the Data

MOUNTED=`grep /etc/mtab -e \/mnt\/backup`
if [ "$MOUNTED" = '' ]; then
        echo "/mnt/backup is not mounted, there is no drive to backup to"
        exit 1
fi


mkdir -p /mnt/backup/cluster_sql

for i in $(echo 'SHOW DATABASES;' | mysql -ubackup -pSUPERSECRET -hData|grep -v '^Database$'); do
  mysqldump -ubackup -pSUPERSECRET -hData --opt $i > /mnt/backup/cluster_sql/$i.sql;
done;

Automatically erase Ruby on Rails session files

Add to your cron:

1 */4 * * *     find /tmp/ -name "ruby_sess*" -cmin +600 -exec rm \{} \;


Deletes sessions over ten hours old every four hours. Otherwise your /tmp will end up overflowing. This only applies you use the file store method of session storage with Rails.
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS