hi,
Im just a novice in shell scripting,can you help me out;
all inbound files will now have timestamp.
the timestamp will be get from a server,specifically on a Moveit server.
any help will do..
thanks.

Recommended Answers

All 3 Replies

Sonja,

I am really not sure of what you are trying to ask. What is a "Moveit server". Are you referring to the modified date vs the creation date?

Hi rch1231,
Thanks for the response.I need a shell script to append a timestamp to all inbound files.I have a shell script but modifications will be done to append timestamp to all inbound files.
see this..

timestamp=`date +"%Y%m%d.%H%M"
  # Archive File
       echo "Archiving $File."
       mv $FullPath/$FileName $ArchDir/${FileName}.${timestamp}
       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

Is it correct,that I already append a timestamp to the files.?
thanks,

1) You should use the code-tags as required by DaniWeb policy. If you do (and assuming I indented as your code was indented orginally), it would look like this. Much nicer, yes?

timestamp=`date +"%Y%m%d.%H%M"
# Archive File
echo "Archiving $File."
mv $FullPath/$FileName $ArchDir/${FileName}.${timestamp}
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

2) There appear to be some errors in your code, which may be because you didn't use the code-tags (??) for instance the timestamp= line is missing the closing back-tick. P.S. If you are using ksh or bash, you are better doing this:

timestamp=$(date +"%Y%m%d.%H%M")

3) I see no declaration of $ParamTmp and $ParamFile and I don't see where they are used prior to your attempt to recover from the error.
4) Your code is fragile: mv command can fail half way through with the source file gone but the target file never created (if, for instance, the target is nfs mounted and full). So you should first create the target file with a cp command, then only if the new file is present and correct, you can remove or rename the original.
5) What is the cd - for? I see no place in the code where you have changed the directory. Scripts should leave you where you started (unless the intent is clearly to move you, e.g. to a work location).
6) Failure might be from other than permissions problems. Error messages should be true before all other considerations (which is sometimes why some compiler error messages are so, umm, useless)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.