Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Written by Julian Rutledge, February 2012.
- ## Licensed for use under the GPL v3
- #!/bin/sh
- #establish working directory and make subdirectory to contain batchfiles
- echo "enter path to directory to be scanned"
- read DIR
- PWD=`pwd`
- mkdir $PWD/batchfiles.d
- #make file list
- ls $DIR | cat -n > $PWD/batchfiles.d/filelist-total.txt
- #create error log
- touch $PWD/batchfiles.d/fnc.errorlist
- #create first list of unscanned files and populate from list of files to be scanned
- cat $PWD/batchfiles.d/filelist-total.txt > $PWD/batchfiles.d/filelist-work.txt
- #set total number of files to be scanned as the first field of last line from the total list
- TOTALNUM=`cat $PWD/batchfiles.d/filelist-total.txt | tail -n1 | cut -f1`
- #initialize cut number variable as total number of files to be scanned
- CUTNUM=$TOTALNUM
- while [ $CUTNUM -gt 0 ]; do
- #grab first line from working list
- FIRSTLINE=`cat $PWD/batchfiles.d/filelist-work.txt | head -n1`
- #set file number number as the first field of first line of the working list
- FILENUM=`cat $PWD/batchfiles.d/filelist-work.txt | head -n1 | cut -f1`
- #set sort field as the fourth field of the first line (delimited by periods) of the working list
- SORTFIELD=`cat $PWD/batchfiles.d/filelist-work.txt | head -n1 | cut -d. -f4`
- # search for period as delimiter in file
- DLIM=`echo $FIRSTLINE | grep "\."`
- #if there is no delimter, wipe the sortfield variable
- if [ "$DLIM" = "" ]; then
- SORTFIELD=""
- fi
- #if the sortfield variable is empty, print the filename to the error log, otherwise continue scanning
- if [ "$SORTFIELD" = "" ]; then
- CUTNUM=$(($TOTALNUM - $FILENUM))
- tail -n$CUTNUM $PWD/batchfiles.d/filelist-total.txt > $PWD/batchfiles.d/filelist-work.txt
- echo $FIRSTLINE >> $PWD/batchfiles.d/fnc.errorlist
- else
- CUTNUM=$(($TOTALNUM - $FILENUM))
- tail -n$CUTNUM $PWD/batchfiles.d/filelist-total.txt > $PWD/batchfiles.d/filelist-work.txt
- fi
- done
- #print errorlist to stdout
- cat $PWD/batchfiles.d/fnc.errorlist
- #clean up temp files
- rm -r $PWD/batchfiles.d
Advertisement
Add Comment
Please, Sign In to add comment