#!/bin/bash # author: Karl Voit, shellscript@Karl-Voit.at # version: v0.1 2003-11 # homepage: http://www.Karl-Voit.at/scripts/ ## This script calls 'time abcde; beep'. 'beep' is some external ## command that plays some sound to gain user's attraction. ## If called with a parameter (a number), the script waits, until ## this amount of MBs are free on the harddisk and then starts the ## command above. ## You can call this script in two ways: ## myabcde -s ## ... starts a new 'abcde'-session when the current one is finished (serial) ## myabcde 535 ## ... starts a new 'abcde'-session when 535 MBs are free (any integer number is fine) # NOTE: this script is a quickhack and you should adopt it to your needs! # Once again: REQUIRES MODIFYING! # 2do: # * check, if used tools are installed # * check, if there is something to check ;-) HARDDISK=hda4 FILENAME=$(basename $0) LOCKFILE="/var/lock/lockfile_$FILENAME" ENDCOMMAND=/usr/bin/apm ENDCOMMANDFILE="/var/lock/doend_$FILENAME" RIPPER=cdparanoia ENCODER=oggenc ## seconds between two attempts (if space-parameter is given) INTERVAL=60 ENCODERCHECKINTERVAL=15 any () { /bin/ps xauwww | /bin/grep -v "grep" | /bin/grep -v "xauwww" | /bin/grep -i $1 } dosay() { echo "$1" | festival --tts & } handle_endcommand() { rm $ENDCOMMANDFILE $ENDCOMMAND } handle_already_locked() { echo "$FILENAME: There is already another instance waiting! Exiting." echo "$FILENAME: If this is not the case, delete the file \"$LOCKFILE\" and restart." exit 1 } handle_another_ripper_running() { echo "$FILENAME: There is already a ripper running (CD-drive occupied)! Exiting." exit 2 } aquire_lock_or_exit() { # exit, if locked [ -e $LOCKFILE ] && handle_already_locked touch $LOCKFILE } dowait_NOENCODER() { # aquire lock aquire_lock_or_exit # to ensure, that the scripts checks, when another abcde-session # changes from one file to another (and therefore no encoder is running) NUMOFENCODERS1=`any $ENCODER |wc -l` sleep $ENCODERCHECKINTERVAL NUMOFENCODERS2=`any $ENCODER |wc -l` while [ $NUMOFENCODERS1 -gt 0 -o $NUMOFENCODERS2 -gt 0 ]; do echo "$FILENAME: There is another encoder currently running ($NUMOFENCODERS1). Will wait until it is finished. ("`date +%Hh%Mm%Ss`")" sleep $INTERVAL NUMOFENCODERS1=`any $ENCODER |wc -l` sleep $ENCODERCHECKINTERVAL NUMOFENCODERS2=`any $ENCODER |wc -l` done echo "$FILENAME: No other encoder running, now starting ... ("`date +%Hh%Mm%Ss`")" beep dosay "Please answer the questions, this tool is about to ask!" # release lock rm $LOCKFILE } dowait_MB() { #echo "$FILENAME: (DEBUG) dowait [$1] called." # aquire lock aquire_lock_or_exit FREESPACEKB=`df|grep $HARDDISK|awk '{print $4}'` FREESPACEMB=`echo "$FREESPACEKB / 1024" | bc` #echo "$FILENAME: (DEBUG) FREESPACEMB=[$FREESPACEMB]" while [ $FREESPACEMB -lt $1 ]; do #echo "$FILENAME: (DEBUG) loop called; FREESPACEMB=[$FREESPACEMB]" SPACEDIFF=`echo "$1 - $FREESPACEMB" |bc` echo "$FILENAME: Current free space is $FREESPACEMB MB. Will wait until $SPACEDIFF MB more are free. ("`date +%Hh%Mm%Ss`")" sleep $INTERVAL FREESPACEKB=`df|grep $HARDDISK|awk '{print $4}'` FREESPACEMB=`echo "$FREESPACEKB / 1024" | bc` done echo "$FILENAME: Current free space is $FREESPACEMB MB. Now starting ... ("`date +%Hh%Mm%Ss`")" beep dosay "Please answer the questions, this tool is about to ask!" # release lock rm $LOCKFILE } case "x$1" in "x-s") dowait_NOENCODER ;; "x") echo "$FILENAME: no parameter detected." ;; *) dowait_MB "$1" ;; esac #echo "$FILENAME: (DEBUG) doing stuff." NUMOFRIPPERS=`any $RIPPER |wc -l` [ $NUMOFRIPPERS -ne 0 ] && handle_another_ripper_running time abcde ; beep abcdestatus [ -e $ENDCOMMANDFILE ] && handle_endcommand echo "$FILENAME: done. ("`date +%Hh%Mm%Ss`")" #end