#!/bin/sh #The script made by dri to rename deleted MH files into valid and readable ones and put them to thetrash folder. # @(#) s1 Demonstrate move and rename. # Provide audit trail for learning and debugging. # Interchange the two debug lines to toggle printing on and off. debug="echo" debug=":" # Set up the test situation. # For production, comment out the remove and create calls. ./remove ./create #You need to modify the script a bit in order to add more folders, if you have any. count() { local a b c d total a=$( ls -1 drafts | wc -l ) b=$( ls -1 inbox | wc -l ) c=$( ls -1 outbox | wc -l ) d=$( ls -1 trash | wc -l ) total=$( expr $a + $b + $c ) echo " total = $total" echo " trash = $d" } count echo DIRS="drafts inbox outbox" echo " Current state:" ls -R $DIRS trash echo $debug " audit trail of operations:" $debug highest=0 for d in $DIRS do for file in $( ls -1 $d/ | grep '^,[0-9][0-9]*$' ) do $debug " Working on $d/$file" n=${file#,} $debug " extracted :$n: from :$file: in :$d:" m=$( expr $n + 0 ) $debug " transformed $n into $m" xform=$m if [ -f trash/$xform ] then highest=$( expr $highest + 1 ) $debug " set highest number to :$highest:" while [ -f trash/$highest ] do $debug " highest increased to $highest" highest=$( expr $highest + 1 ) done mv $d/$file trash/$highest $debug " moved (bumped) $d/$file to trash/$highest" else # echo mv $d/$xform trash mv $d/$file trash/$xform $debug " moved $d/$file to trash/$xform" highest=$xform $debug " set highest number to :$highest:" fi done done echo echo " Final state:" ls -R $DIRS trash echo count exit 0