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

About this user

fak3r http://fak3r.com

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

Populate titlebar in any term

Populate your titlebar in any term with some useful info such as uname -a, architecture, if you're ROOT or not, etc. In Linux:
#!/bin/bash
HOST_NAME=`hostname -f`
if [ `id -u` = 0 ]; then
OPT=”`uname` (`uname -a | cut -f12 -d’-`) - ROOT USER”
else
OPT=”`uname` (`uname -a | cut -f12 -d’-`)”
fi
REPLACE=”${HOST_NAME} - ${OPT}”
echo -n -e “\033]0; $REPLACE \007echo${REPLACE}”
exit 0

Then run this script, and your termtitle will be something like the following:
Servername (Linux / x86_64).

For Solaris it needs to be done a bit differently:
#!/usr/local/bin/bash
HOST_NAME=`uname -a | cut -f2 -d’-`
OPT=”(`uname -a | cut -f1 -d’-` / `uname -a | cut -f6 -d’ ‘`)”
REPLACE=”${HOST_NAME} - ${OPT}”
echo -n -e “\033]0; $REPLACE \007 “
echo “${REPLACE}”
exit 0

Add/remove things from the OPT= line to customize. To test it, just issue the command on the commandline without the ()'s to see what it'll look like.

Remove comments from a file

Remove all comment lines from a file.

sed -e '/^#/d' $1 | more

or to output it to a new file
sed -e '/^#/d' $1 > $1.nocomments

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
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS