% #!/bin/sh % % export curdate=`date +%d%m%y` % export reject=`date +%d` Many /bin/sh shells do *not* support the bash-extension of setting a variable and exporting it at the same time. The date arguments are not quoted properly. In this case, it's probably going to work, but it's safer to use quotes. curdate=` date '+%d%m%y' ` export curdate reject=` date '+%d' ` export reject % mount /log-stale % cd /log-stale % mkdir HOSTS % cd /log-stale/HOSTS No error-checking :( I'd probably start with something like: err() { errcode="$1" shift if test -z "${errcode}" ; then errcode=1 fi } and use it every time an operation fails: stalelogdir="/log-stale" hostdir="${stalelogdir}/HOSTS" mount "${stalelogdir}" if test $? -ne 0 ; then err 1 "${stalelogdir}: cannot mount" fi if test ! -d "${hostdir}" ; then mkdir -p "${hostdir}" if test $? -ne 0 ; then umount "${stalelogdir}" err 1 "${hostdir}: cannot create directory" fi fi % for i in ls /log-fresh/HOSTS/*/*/*/ ; do if [[ ls $i != /log-fresh/HOSTS/*/*/reject ]]; then mv $i /log-stale/HOSTS/ fi ; done Indentation is 90% of the readability of a source file. Please wrap lines to a more reasonable length. Another tricky point here is that if there are too many matches in the filename wildcard, you will hit command-line limits. It's usually better to feed filenames one by one to a reader loop: find /log-fresh/HOSTS -type d | \ while read dname ; do # Perform something in directory "${dname}" done % tar -cf logs_$curdate.tar /log-stale/HOSTS/ % bzip2 logs_$curdate.tar % rm -rf /log-stale/HOSTS/ % cd / % umount /log-stale % exit 0 No error checking here either :(