Re: How to test the presence of a file and the date of its creation?



On 2006-06-21, NSIMBA Guy wrote:
Hi,

I would like to write a script which will test the existence of a file and
there creation date (file creation to day).

The creation date is not stored in a Unix filesystem. You can get
the last-modified, last-status-change or the last-access date.

- If the file is present and creation to day, the programm continuous (Code
return 0)

- If the file is not present, the program stops (code return 1).

- If the file is present but the current date does not carry, the program
stops (code return 2)

But I have difficulty to transform into code the test of the file and date
of his creation.

Here my script. Thanks for helping me to make it achievable

Thank you to correct my script because it does not good.

#!/bin/sh
# "mapasa" c'est le nom de mon fichier

if [-f file ] and [file (created to day)]"; then echo "file exist and the
programm continuous"
fi
Exit 0

There is no command called 'Exit'; I presume you mean 'exit'.

if [!-f mapasa] then echo "file not exist"

You need a space after '[' and after '!' and before ']'. You also
need a semi-colon or a newline before 'then'.

fi
Exit 1

if [-f mapasa] and [file (created to day] then echo "file is an old file"
fi
Exit 2

touch -t `date +%m%d0000` tempfile
if [ -f "$file" ]
then
if [ -n "$(find "$file" -newer tempfile)" ]
then
exit 0
else # If the file is present but the current date does not carry,
# the program stops (code return 2)
exit 2
fi
else ## If the file is not present, the program stops (code return 1).
exit 1
fi
rm tempfile

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • How to test the presence of a file and the date of its creation?
    ... there creation date. ... If the file is not present, the program stops. ... Here my script. ... Exit 0 ...
    (comp.unix.shell)
  • Re: Are vbscript classes fast?
    ... Generally speaking, there is an overhead cost to creating a new scope, be it a function or a class, but the mere act of creating the scope is fairly rapid. ... I compared a generic function that just returned an empty value written in script and written as a method of a compiled component, and not surprisingly, the script function was slower by a factor of two - most likely due to scope creation. ... The MOST expensive way to create an object is to use WScript.CreateObject or Server.CreateObject instead of the native CreateObject in VBScript. ...
    (microsoft.public.scripting.vbscript)
  • Re: Remove duplicate files [POSIX script]
    ... I added in a hurry before I posted the script. ... In addition to the algorithmic complexity one should also note that ...
    (comp.unix.shell)
  • Re: Changing a users password non-interactively?
    ... You need expect and a setpass.expect script which ill add ... exit with a nasty warning. ... # Be careful of the COMMAND and UNDOCMD - they are dependant on your ...
    (comp.unix.aix)
  • Re: script does not always work the same each time.
    ... I have written a simple script to test code build and test run on a ... $lineterminationChar {append output $expect_out; ... exit 1;} ...
    (comp.lang.tcl)