Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move yesterday's file the next day

Status
Not open for further replies.

confuseddddd

Programmer
May 22, 2003
53
US
Need some help on taking a file created yesterday but is processed today and moving it to an archive directory.

correctly the logic is:
cp 20*.I* /ARCHIVE/inbound/cp 20*.I* 2>> $EDILOG

but we receive:
cp: 20040218.I01: Error 0

Any ideas on how to copy the file regardless of the date???
Thought the wildcard would work but doesn't appear to...
 
cp 20*.I* /ARCHIVE/inbound/cp/ 2>> $EDILOG

Jean Pierre.
 
Have you tried this ?
cp 20*.I* /ARCHIVE/inbound 2>> $EDILOG

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
tried your suggestions and still am receiving the ERROR 0.
The script is run daily and needs to take the day before's file and place in an archive directory. Don't want to hard code the date every day but wanted to just be able to copy the file (yesterday's)...

Any other suggestions????
 
try this

LASTFILE=`ls -rt 20*.I*|line`

mv $LASTFILE /ARCHIVE/inbound/cp
 
Here's a script we use on some of our servers called logmaint. It copies all files in a log directory to a log.archive directory which contains a subdir for each day of the week. The -w option specifies how many weeks back you want to save, and the -c, -m, and -z options specify whether you want the original file moved, copied, or zeroed out.

Dennis

Code:
#!/bin/sh
#

QUIET=0
WEEKS=0
MODE="zero"

while getopts qcmzw: opts
do
        case $opts in
        q) QUIET=1;;
        c) MODE="copy";;
        m) MODE="move";;
        z) MODE="zero";;
	w) WEEKS=$OPTARG;;
        esac
done

shift `expr $OPTIND - 1`

if [ "$1" = "" ]
then
	echo "usage: $0 [-q] [-w numweeks] [-c|-m|-z] logdir "
	echo "ERROR: missing argument logdir "
	exit 1
fi

LOGDIR=$1
LOGHOME=${LOGDIR}.archive

if [ ! -d ${LOGDIR}  ]
then
	if [ $QUIET = 1 ]
	then
		exit 0
	else
		echo "usage: logmaint.sh logdir "
		echo "ERROR: '${LOGDIR}' is not a directory "
		exit 1
	fi
fi


if [ ! -d  ${LOGHOME} ]
then
	/bin/mkdir ${LOGHOME}
	if [ $? -ne 0 ]
	then
		echo "ERROR: failed to create ${LOGHOME}"
		exit 1
	fi
fi

if [ $WEEKS = 0 ]
then
	DAYOFWEEK=`date | cut -f1 -d" "`
	DSTDIR=${LOGHOME}/$DAYOFWEEK

	if [ ! -d  ${DSTDIR} ]
	then
		/bin/mkdir ${DSTDIR}
		if [ $? -ne 0 ]
		then
			echo "ERROR: failed to create ${DSTDIR}"
			exit 1
		fi
	fi

	/bin/rm -r ${DSTDIR}/* > /dev/null 2>&1

	/bin/cp -rp ${LOGDIR}/* ${DSTDIR}
	if [ $? -ne 0 ]
	then
		echo "ERROR: failed to copy '${LOGDIR}' to '${DSTDIR}'"
		exit 1
	fi
else
	DSTDIR=${LOGHOME}/week1

	/bin/rm -rf ${LOGHOME}/week${WEEKS}

	while [ $WEEKS -gt 1 ]
	do
		NEXT=$WEEKS
		WEEKS=`expr $WEEKS - 1`

		if [ -d ${LOGHOME}/week${WEEKS} ]
		then
			/bin/mv -f ${LOGHOME}/week${WEEKS} ${LOGHOME}/week${NEXT}
		fi
	done

	/bin/mkdir ${LOGHOME}/week1
	/bin/cp -rp ${LOGDIR}/* ${LOGHOME}/week1

	if [ $? -ne 0 ]
	then
		echo "ERROR: failed to copy '${LOGDIR}' to '${DSTDIR}'"
		exit 1
	fi
fi

if [ $MODE = zero ]
then
	find ${LOGDIR} -name "*" -print  > /tmp/cleanloglist.${$}

	for name in `cat /tmp/cleanloglist.${$}`
	do
		if [ -f $name ]
		then
			/bin/cat /dev/null > $name
		fi
	done

	/bin/rm -f /tmp/cleanloglist.${$}

elif [ $MODE = move ]
then
	/bin/rm -rf ${LOGDIR}/*
fi

exit 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top