Adding timestamp to all inbound files

hi,
can someone give me a sample shell scripts to make all inbound files will a have a Moveit timestamp.I think MoveIt is a server,thanks.

Hi Sonja,

You need to give more information.

Where are your files coming from?
Where do you want the timestamp? In the filename? Appended to the file? In a logfile?

I don't know what MoveIt is. If no one answers, maybe no one else does either.

hi ken, thanks for the response,I have to modify my shell script to append timestamp to all inbound files.

---------- Post updated at 08:11 PM ---------- Previous update was at 08:02 PM ----------

# Archive File
echo "Archiving $File."
mv $FullPath/$FileName $ArchDir/${FileName}.${datestamp}
RetCode=$?
if [ $RetCode -ne 0 ]
then
echo "Not enough permission to move the file $FileName."
mv $ParamTmp $ParamFile
cd -
exit 1
else
echo "Was able to successfully archive the file $FileName."
fi

   count=\`echo $count \+ 1 |bc\`
fi

OK, you said append. So these are text files and you want to add one more line of text with the timestamp, right?

Run man date and pick a format you like. Then run a command like this:

date +%c >> filename
or
date "+%F %T" >> filename

---------- Post updated at 09:19 PM ---------- Previous update was at 09:13 PM ----------

OK, to put the date in the filename, try this:

mv $FullPath/$FileName $ArchDir/${FileName}.$(date +%Y%m%d)

BTW, you can increment count like this:

((count++))

hi ken,
thanks again...
how can i append a timestamp to the file,i just only show you the date,
is it something like this...

datestamp=`date +"%Y%m%d.%H%M"`

and for timestamp..

timestamp=$( date +%d%m%y%H%M%S )
should i only chnage the datestamp to timestamp on this...?

mv $FullPath/$FileName $ArchDir/${FileName}.${timestamp}
please correct me if I'm wrong..
ken
thank you...=)

You have to decide what format you want for the timestamp and/or datestamp.

%Y is the 4-digit date,
%H is the (24-hour) hour, etc.

You can see all the format options by executing man date and scrolling down to the list.
And you can experiment right on the command line to see what it would look like. e.g.:
date +%H%M%S

1 Like