Never been to TextSnippets 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 (or not, you can keep them private!)

About this user

Ryan Schwartz http://ryanschwartz.net/

« Newer Snippets
Older Snippets »
6 total  XML / RSS feed 

Rolling Apache Logfiles

This is a little snippet I whipped up long ago to roll our logs, feel free to use...

#!/bin/sh

/usr/bin/grep CustomLog /usr/local/etc/apache2/httpd.conf |/usr/bin/grep -v \#|/usr/bin/awk '{print $2}'|/usr/bin/sort|/usr/bin/uniq|/usr/bin/grep -v /var/log > logfiles
/usr/bin/grep ErrorLog /usr/local/etc/apache2/httpd.conf |/usr/bin/grep -v \#|/usr/bin/awk '{print $2}'|/usr/bin/sort|/usr/bin/uniq|/usr/bin/grep -v /var/log >> logfiles
/usr/local/bin/weblog_rotate.pl --loglist logfiles --touchlog --restart_cmd "/usr/local/etc/rc.d/apache2.sh restart" --compress --days 120


The weblog_rotate.pl is a script from Uthe Urchin folk, available at http://download.urchin.com/support/weblog_rotate.pl

blastwave package blaster

for a list of packages, install them all please - no questions asked

for z in `cat pkgs`
do
  echo "#######################"
  echo installing $z...
  echo "#######################"
  yes | pkg-get -i $z
done

zfs migration script

First rev, works but could use improvement

#!/bin/bash
if [ $# -ne 2 ]
then
    echo "Usage: $0 host_to_send_to zpool_name_on_destination"
    exit
fi
SERVER=$1
ZPOOL=$2
echo
echo "*********************************************************************************"
echo "*                                                                               *"
echo "* Please note, this wrapper only creates migration scripts for filesystems with *"
echo "* existing snapshots. If you want to migrate a snapshot-less filesystem, just   *"
echo "* run 'zfs snapshot zpool/filesystem@migrate' to create a snapshot which will   *"
echo "* allow this script to transfer it to the destination zpool.                    *"
echo "*                                                                               *"
echo "*********************************************************************************"
echo
if [ -f ./tmp/${SERVER}.screens ]
then
echo
echo "******************************************************************************"
echo "*"
echo "* Sorry, tmp/${SERVER}.screens exists, please run 'rm tmp/*' and try again..."
echo "*"
echo "******************************************************************************"
echo
exit
else
if [ ! -d tmp ]
then
mkdir tmp
fi
fi
for z in `zfs list | grep @ | awk '{print $1}' `;
do
FSNAME=`echo $z | awk -F@ '{print $1}' | awk -F/ '{print $NF}'`
if [ -f tmp/${FSNAME}.migrate ] 
then
echo "zfs backup -i $PREV $z | ssh root@$SERVER zfs restore $ZPOOL/${FSNAME}" >> tmp/${FSNAME}.migrate
PREV=$z
else
echo "Processing snapshots for ${FSNAME}."
echo "zfs backup $z | ssh root@$SERVER zfs restore $ZPOOL/${FSNAME}" > tmp/${FSNAME}.migrate
echo "screen -m -d bash tmp/${FSNAME}.migrate" >> tmp/${SERVER}.screens
PREV=$z
fi
done
echo
echo "**************************************************************************"
echo "*"
echo "* Ok, all finished - You can either run them individually, or simply type"
echo "*"
echo "* bash tmp/${SERVER}.screens"
echo "*"
echo "* at a prompt to run them concurrently in disconnected screen sessions."
echo "*"
echo "**************************************************************************"
echo

World clock shell script

#!/bin/sh
TZ=US/Pacific date +"Jason/Nate: %I:%M %p %a %D"
TZ=US/Central date +"Ryan: %I:%M %p %a %D"
TZ=US/Eastern date +"Jan/Daniel: %I:%M %p %a %D"
TZ=US/Eastern date +"Terrel/Christopher: %I:%M %p %a %D"
TZ=UTC date +"UTC/GMT: %I:%M %p %a %D"
TZ=Europe/Amsterdam date +"Filip/Marten: %I:%M %p %a %D"
TZ=Europe/Amsterdam date +"Florian/Johan: %I:%M %p %a %D"
TZ=Europe/Paris date +"Dean/Damelon: %I:%M %p %a %D"
TZ=Australia/Melbourne date +"Justin: %I:%M %p %a %D"
TZ=NZ date +"Koz: %I:%M %p %a %D"

killing your own dispatch.fcgis

ps aux|grep youruser|grep dispatch|awk '{print $2}'|xargs kill -9

of course you can use this for any process and just change the 'dispatch' part

delete a filename starting with a dash

Have you ever created a file by mistakenly adding a flag where you shouldn't? Find the inode number of the file and delete it using find:

[one:~/src/oops] ryanschwartz$ cp test -p
[one:~/src/oops] ryanschwartz$ ls
-p test
[one:~/src/oops] ryanschwartz$ rm -p
rm: illegal option -- p
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
[one:~/src/oops] ryanschwartz$ \rm -p
rm: illegal option -- p
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
[one:~/src/oops] ryanschwartz$ ls -li
total 0
5937393 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 -p
5937392 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 test
[one:~/src/oops] ryanschwartz$ find . -inum 5937393
./-p
[one:~/src/oops] ryanschwartz$ find . -inum 5937393 -exec rm {} \;
[one:~/src/oops] ryanschwartz$ ls -li
total 0
5937392 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 test
« Newer Snippets
Older Snippets »
6 total  XML / RSS feed