Please note that some commands can cause badly damage when used/changed not properly. Always keep a recent backup at hand.
.DS_Store contains informations on how to display folders; e.g. list view. Such files are of no use for Linux- and Windows-users. The following command finds all .DS_Store-files in the current directory and every subdirectory and deletes it immediately. I put it in a cron-job, which is performed every five minutes.
find . -type f -name .DS_Store -exec rm -f '{}' ';'
The next thing is about these fucking Resource Forks. If I could, I would travel back through time and eliminate the person who created it. Anyway, they're among us now, and we can't get rid of'em. Well, at least they serve no needs on a Linux-server, so it's (usually) safe to delete them. As example, if you drag photos from iPhoto to a Samba-Share, not only the JPGs are stored, but also ._
find . -type f -name ._* -exec rm -f '{}' ';'
My linux servers hosts my complete electronic Music Library, sharing it using daapd. All downloads come with a mess of additional files like covers, cue-sheets, nfo-files etc. Usually, I'm too lazy to get rid of'em directly after the download. As time passed by, everything got messed up with every new album I've leeched. Instead of going through every directory - and there are many of them - I used another fine find-command to remove anything not an mp3-file within my MP3-Folder:
find . -type f \! -name "*.mp3" -exec rm '{}' ';'
In my special case, I used the following command to separate thumbnails (expected smaller than 10KB) and closeups (expected to be greater than 10KB) in a web-dump.
find . -type f -name "*.jpg" -size +10240c -exec mv '{}' ~/newdir/ ';'
With this little script, you can batch rename directories in current folder AND subfolders
#!/bin/sh SEARCH="set" REPLACE="s" for ITEMOLD in `find . -type d` do echo "Processing '$ITEMOLD'" ITEMNEW=`echo $ITEMOLD | sed "s/$SEARCH/$REPLACE/g"` #echo "After search/replace: '$ITEMNEW'" if [ $ITEMOLD != $ITEMNEW ] then if [ ! -d "$ITEMNEW" ] then echo "Attempting to rename '$ITEMOLD' to '$ITEMNEW'" mv "$ITEMOLD" "$ITEMNEW" if [ ! -d "$ITEMNEW" ] then echo "[-] Renaming seems to have failed - '$ITEMNEW' doesn't exist" exit 1 else echo "[+] Success" fi else echo "[-] '$ITEMNEW' already exists" fi else echo "[i] '$ITEMOLD' does not match expression, skipping" fi echo "" done exit 0
When the end of the semester gets close, I usually get into a rush and try to download all online material of the lectures. Being tired of clicking through thousands of pages, I remembered wget. A very useful tool, not just to download ... err ... thumbs and their linked close-ups ;-)
The following command will do the trick:
wget -r -np -nd <url>
You end up having all links recursively downloaded -r, but tell wget not the step up a level -np, and finally, we don't want to have put the files in nested directories -nd. That's it, alreay, straight and steady.
To just download files of special type, I recommend adding the following switch:
wget -r -np -nd -A *.pdf <url>
Recently, I accidentally deleted a vital file on my linux server. Thanks to my regular backups by mkcdrec I just needed to have a look for the backup CD. After googling a few minutes, I came out with the appropriate shell command to extract the desired file out of a gzipped tar-archive:
tar -xzv --file=/Volumes/CDrec-29.07.2005/sdb1._var.tar.gz ./www/partyguide/curl/config.txt
This command recreated the directory structure in the current working dir (make sure you're not cd-ed into the CD mount point, otherwise it can't write out).
Sometimes I'm running amok with
chmod -R 644 .without thinking it thouroughly. So folders get lost of their execute-flag, and nobody can enter them anymore. Well, here's the solution:
find . -type d -exec chmod u+x '{}' ';'
Somehow, the dump get's fucked up because of the line endings. They're all converted to \r. If you're trying to restore the dump on a linux machine, nothing works. If you use the following command, everything should be fine:
tr '\015' '\012' < dump-mac.sql > dump-linux.sql
The other way 'round ... Converting linux- to mac-files:
tr '\012' '\015' < unix-format-file > mac-friendly-file
After you've treated your dumps, insert'em into your database:
mysql --user=user --password=password database < dump-linux.sql
To do this, you need to get Mp3splt and compile it yourself. Don't worry, it's easy (otherwise, I couldn't have made it 'til here ;-). Check the manual for proper installation steps.
mp3splt -c sheet.cue audio.mp3
Recently, I had to replace a URL linking to a no longer accurate place in hundreds of HTML-Files (yeah, this sites origin dates even before ST:ENT started. Terrible!).
Well then, I had two choices: Download anything onto my machine, look out for a nice GUI-editor which allows search & replace for whole folders or ... well, dive into the web and put a nice shell-script together which does the work for me. Since GUIs are for kids and professors, i chose the second option. Here is the result (you surely notice how much safety measures I took. In the final version, i disabled creation of .tmp-Files, because it would have messed everything even more. I had luck - everything worked out the way I expected it to ;-):
#! /bin/sh STRSEARCH="www.unibe.ch\/faculties\/humanities_d.html" STRREPLACE="www.philhist.unibe.ch\/" if [ -d /var/www/hist ] then # AT HOME cd /var/www/hist else # ON UBECX cd /u/hist/www fi find . -type f -name '*.htm' -print | while read i do cp "$i" "$i.tmp" if [ -f "$i.tmp" ] then #echo "s/$STRSEARCH/$STRREPLACE/g" sed "s/$STRSEARCH/$STRREPLACE/g" "$i" > "$i.new" if [ -f "$i.new" ] then mv "$i.new" "$i" else echo "$i.new doesn't exist" fi else echo "$i.tmp wasn't created" fi done
Please be aware to use the special rsync-Version written for Mac OS X (fucking resource forks, again!). Otherwise you could end up with a mess (only on the backup side, but this sucks as much!).
I separated iPhoto-Files from the rest, because the .sparseimage wouldn't fit on a DVD anylonger.
backup.sh
#!/bin/sh
if [ $# -lt 1 ]
then
echo "Please provide a destination to store the backup to:"
echo "fwdsk (Firewire-Drive)"
echo "eth (Server-Share)"
echo "tmp (/tmp)"
exit 1
fi
case $1 in
"fwdsk")
IMAGEFOLDER="/Volumes/TRANSFER";;
"eth")
IMAGEFOLDER="/Volumes/RSYNC";;
"tmp")
IMAGEFOLDER="/tmp";;
*)
echo "Please provide a destination to store the backup to:"
echo "fwdsk (Firewire-Drive)"
echo "eth (Server-Share)"
echo "tmp (/tmp)"
exit 1;;
esac
if [ ! -d "$IMAGEFOLDER" ]
then
echo "Directory '$IMAGEFOLDER' not found"
exit 1
fi
BACKUPINFO=( "home" "iphoto" )
for VOLNAME in ${BACKUPINFO[@]}
do
DISKIMAGENAME="$VOLNAME"
DISKIMAGEPATH="$IMAGEFOLDER/$VOLNAME.sparseimage"
BACKUPSOURCEFILE="/Users/mario/Rsync/bkpsrc/$VOLNAME.txt"
if [ ! -f "$BACKUPSOURCEFILE" ]
then
echo "File '$BACKUPSOURCEFILE' not found"
exit 1
fi
BACKUPSOURCE=`more $BACKUPSOURCEFILE`
BACKUPDESTINATION="/Volumes/$VOLNAME"
RSYNCEXCLUDE="/Users/mario/Rsync/exclude/$VOLNAME.txt"
#-------------------------------------------------
# Create/reuse & mount Disk-Image
#-------------------------------------------------
if [ ! -f "$DISKIMAGEPATH" ]
then
# Disk-image-file doesn't even exist - create it
echo "Creating disk image \"$DISKIMAGEPATH\""
hdiutil create -fs HFS+ -type SPARSE -size 20g -volname "$DISKIMAGENAME" "$DISKIMAGEPATH"
else
echo "Using pre-existing disk image \"$DISKIMAGEPATH\""
fi
if [ ! -d "$BACKUPDESTINATION" ]
then
# Disk-image doesn't seem to be mounted
hdiutil attach "$DISKIMAGEPATH"
fi
#-------------------------------------------------
# Did Disk-Image mount correctly?
#-------------------------------------------------
if [ ! -e "$BACKUPDESTINATION" ]
then
echo "There was a problem creating or mounting the disk image"
exit 1
fi
#-------------------------------------------------
# Rsync
#-------------------------------------------------
/Users/mario/Rsync/rsync.sh "$BACKUPSOURCE" "$BACKUPDESTINATION" "$RSYNCEXCLUDE"
#-------------------------------------------------
# Unmount Disk-Image and do maintenance operations
#-------------------------------------------------
# hdiutil info | grep /Volumes/$VOLNAME | cut -f 1
#
# Expected output: /dev/disk2s2 Apple_HFS /Volumes/Rsync-Backup
# ^ this info is required to unmount
DISKIMAGEDEVICE=`hdiutil info | grep /Volumes/$VOLNAME | cut -f 1`
echo "Disk image mounted as $DISKIMAGEDEVICE"
hdiutil detach -quiet "$DISKIMAGEDEVICE"
echo "Disk image ejected"
hdiutil compact "$DISKIMAGEPATH"
echo "Disk image compacted"
done
rsync.sh
#!/bin/sh if [ $# -ne 3 ] then echo "Usage:" echo "rsync.sh" exit 1 fi BACKUPSOURCE="$1" BACKUPDESTINATION="$2" RSYNCEXCLUDE="$3" if [ ! -d "$BACKUPSOURCE" ] then echo "Source directory '$BACKUPSOURCE' not found" exit 1 fi if [ ! -d "$BACKUPDESTINATION" ] then echo "Destination directory '$BACKUPDESTINATION' not found" exit 1 fi if [ ! -f "$RSYNCEXCLUDE" ] then echo "Exclude file '$RSYNCEXCLUDE' not found" exit 1 fi # --verbose # --showtogo # --dry-run time sudo /usr/local/bin/rsync -a --delete --delete-excluded --eahfs --showtogo --exclude-from\ "$RSYNCEXCLUDE" "$BACKUPSOURCE" "$BACKUPDESTINATION"
bkpsrc/home.txt
/Users/mario/.
bkpsrc/iPhoto.txt
/Users/mario/Pictures/iPhoto Library/.
exclude/home.txt
Music/ Movies/ PoisonDownloads/ Cache/ Caches/ .Trash/ Fun-Stuff/ .DS_store iPhoto Library/
exclude/iphoto.txt
.Trash/ .DS_store
Mail.app is a nice, sleek E-Mail-Client which does quite everything you need in everydays use. But there's one great drawback: Apple engineers sometimes simply miss the point. When accessing IMAP-mailboxes through Mail.app, you're not only presented all the expected IMAP-folders, but all those crappy dot-hidden-files (.*) in the IMAP-root, even if there is a .mailboxlist, which tells well written (!) Mail-clients which folders to subscribe to (isn't it even mentioned in a RFC?). Mail.app doesn't - god knows why. In fact, it seems also to depend on which mail-server your provider uses. If it's pmdf, you're most likely to end up the way I am. Another provider I use to store my eMeidi.com-accounts on, there are no such issues at all.
Anyway, while browsing the web I only found some small hints ... one worked! There's some manual work to do, so it's essential to have SSH-/Telnet-Access to the server where your folders are being stored.
for i in {debug,info,notice,warning,err,crit,alert,emerg}
do
logger -p daemon.$i "Test daemon message, level $I"
done
Hint taken from oreilly.de
#!/bin/sh # brought to you by eMeidi.com, 2005 v0.1beta # feel free to distribute this piece of software # licensed under gnu general public license # check whether two vars were passed to the shell-script if [ $# -lt 2 ] then echo "You need to provide a path to an .html-file." exit 1 fi # check whether the source html-file exists if [ ! -f "$2" ] then echo "File '$2' not found." exit 1 fi # get application-directory cd "$1" APPDIR=`echo $PWD` RESDIR="$APPDIR/Contents/Resources" # configure binary/config-file locations (inside the .app-folder) TIDYBIN="$RESDIR/tidy" TIDYCONF="$RESDIR/tidy.conf" if [ ! -f "$TIDYCONF" ] then echo "Configuration file '$TIDYCONF' not found." exit 1 fi # since there always happens shit(tm), backup the source file before tidying it SEARCH=".htm" REPLACE=".old.htm" BKPFILE=`echo $2 | sed -e "s/$SEARCH/$REPLACE/"` mv "$2" "$BKPFILE" # only proceed when the backup has been created if [ ! -f "$BKPFILE" ] then echo "Couldn't create backup file." exit 1 fi # well, here we are - let's go $TIDYBIN -config "$TIDYCONF" "$BKPFILE" > "$2"Platypus 3.0
The following script helps me to update all instances of a custom-built CMS on my local server. Since the CMS is shared by almost 10 different web-sites now, it becomes very time consuming to update changed files manually.
#!/bin/sh echo "eMeidi.smt-Upgrader v0.1" echo "(c) by Mario Aeby, eMeidi.com" echo "" if [ $# -lt 1 ] then echo "Usage: $0" exit 1 fi WWWROOT="/var/www/" PROJECTS="kiesen neuenegg dkf wsu tierstall spneuenegg schmid-baeume privatcoaching sek uhc" FILES="admin/inc/emeidi_smt.lib.php admin/inc/stylesheet.css admin/tools/table_editor.php admin/tools/photo_gallery.php" if [ ! -d $WWWROOT ] then echo "'$WWWROOT' doesn't exist." exit 1 fi SOURCEDIR=$WWWROOT$1"/" if [ ! -d $SOURCEDIR ] then echo "'$SOURCEDIR' doesn't exist." fi for PROJECT in $PROJECTS do PROJECTDIR=$WWWROOT$PROJECT"/" if [ ! -d $PROJECTDIR ] then echo "$PROJECTDIR doesn't exist." exit 1 fi for FILE in $FILES do SOURCE=$SOURCEDIR$FILE DEST=$PROJECTDIR$FILE if [ ! -f $SOURCE ] then echo "Source file '$SOURCE' not found." exit 1 fi if [ ! -f $DEST ] then echo "Destination file '$DEST' doesn't exist. Creating dummy because of programmers lazyness." touch $DEST fi if [ $SOURCE = $DEST ] then echo "Source path is identical to destination path, skipping '$DEST'." continue fi COMPARE=`cmp "$SOURCE" "$DEST"` COMPARELEN=`expr length "$COMPARE"` if [ $COMPARELEN -lt 1 ] then echo "Source and Destination-File seem to be identical. Skipping '$DEST'." continue fi DESTBKP=$DEST".bak" if [ -f $DESTBKP ] then echo "Previous backup found, trying to remove '$DESTBKP'" #mv "$DESTBKP" "$DESTBKP.bak" rm "$DESTBKP" fi if [ -f $DESTBKP ] then echo "Could not remove previous backup. Aborting." exit 1 fi mv "$DEST" "$DESTBKP" if [ ! -f $DESTBKP ] then echo "Could not create backup copy. Aborting." exit 1 fi echo "Trying to copy '$SOURCE' to '$DEST' ..." cp "$SOURCE" "$DEST" if [ ! -f $DEST ] then echo "Although copied, it seems that '$DEST' hasn't been created. Aborting." exit 1 else echo "Success: '$DEST' copied." fi done echo "" done exit 0
dpkg-deb -x <package>.deb <destination-dir>
/lib/libwrap.so.0 /usr/lib/libucdagent-0.4.2.so /usr/lib/libucdmibs-0.4.2.so /usr/lib/libsnmp-0.4.2.so /usr/sbin/snmpd
Recently, I noticed msnbot was spamming my whole upload bandwidth because it seemed to create a complete dump of my photo gallery - several image requests within a minute! After some googling I discovered several Apache modules which promise to get rid of such bots running amok (although there are some concerns about artificially prolonging download times for leechers - beware!). I finally decided to go on with mod_bwshare. In a temporary "dust of war", I got the wrong impression that I needed to upgrade to Apache 2.0.x to be able to get a precompiled .deb. Well, haha! There isn't a debian package available right now. Well, okey, at least I'm running the newest Apache now, although I had to
apt-get remove apache dpkg-reconfigure php4 dpkg-reconfigure php4-mysql dpkg-reconfigure php4-curl dpkg-reconfigure php4-imap dpkg-reconfigure php4-gd
to get back to my "touched working system" and make PHP aware of Apache 2. Be aware: Everything starts with untouched config files, so make sure you enable error logging in PHP again. Especially if you're a web-dev like I am, you know about usefulness of
error_reporting = E_ALL
Okey, now straight back to the task. Since all this stuff is open source, we could at least give it a try with compiling and stuff (honestly, I just now enough about compiling to completly havoc a system, but I was a lucky guy in this case). So download the source files:
cd /tmp wget http://www.topology.org/src/bwshare/bwshare-0.1.3.zip unzip bwshare-0.1.3.zip
So, there we had'em now, hundreds of lines of codes. As stated on the developers homepage itself, running
cd src/modules/bwshare apxs2 -c mod_bwshare.c apxs2 -i mod_bwshare.la
Should do the trick. Nada, first we needed the developer package:
apt-get install apache2-dev
Once again:
apxs2 -c mod_bwshare.c apxs2 -i mod_bwshare.la
A lot of warnings were displayed, but finally, I read
... chmod 644 /usr/lib/apache2/modules/mod_bwshare.so
After having succesfully compiled mod_bwshare, I had to create two text-files in /etc/apache2/mods-available/
bwshare.load bwshare.conf
and pasted the following contents:
LoadModule bwshare_module /usr/lib/apache2/modules/mod_bwshare.so
# Some bandwidth control parameters. BW_tx1cred_rate 2 BW_tx1debt_max 10 BW_tx2cred_rate 1000 BW_tx2debt_max 1000000 <Location /bwshare-info> SetHandler bwshare-info </Location> <Location /bwshare-trace> SetHandler bwshare-trace </Location> </IfModule>
That was it (if you got that far, you surely know now what comes next - putting symlinks in mods-enabled/ and doing a
apache2ctl graceful
(Thanks to our solaris master Aeschlimann at the University for the graceful hint some time ago - greetz).
It took me some time to figure out: Press and hold the 'Apple'-key and doubleclick on the Appliction icon (Note: This only seems to work with 'Battlefield 1942.app' and not with 'Battlefield 1942 The Road To Rome.app'). Instead of launching the game, a small dialogue box comes up, where you can set the monitor on which the game should be displayed (aside, there are some other nice features like: play windowed, set resolution and refresh rate).
A lot of googling didn't help - some sites mention the ~ key, others state ^ should be pressed, the third thinks it's better to press the key above tab - nevermind, it's < > on Mac!
Ever wondered how to preset video output screen in VLC (Videolan Client) permanently instead of switching to device two every time you fire up the client (Video > Video device > Screen 2)? I finally found the following hint at a support mailing list of the videolan developers:
The default screen can be set under preferences > modules > interface > video device
HP provides a variety of software solutions to set up or manage your HP Jetdirect-connected network printers. more...
#CH 12 27 94 91 9









