is there built-in ksh functionality to check if file timestamp has changed

is there built-in ksh functionality to check if file timestamp has changed

Post by terry433.. » Wed, 26 Jan 2005 18:17:06



say I have a flag (file) that I'm waiting for to change and - when it
does - will carry out a series of actions. Currently I use ls() on the
flag and loop running ls() until flag changes - I simply diff the
output of the two ls commands to determine when the flag has changed
but feel this is kindof primitive, code example is as follows :-

flag=`ls $remote_file`
is_flag_present="false"

while [ "$is_flag_present" != "true" ]; do
new_flag=`ls $remote_file`
if [ "$new_flag" != "$flag"]; then
is_flag_present="true"
fi
done

can anyone suggest a better way to test if a file changes timestamp
(not size, file is only touched to indicate a change) or any in-built
ksh test that would be more appropriate and better syntax than above
code block

 
 
 

is there built-in ksh functionality to check if file timestamp has changed

Post by Rakesh Sharm » Wed, 26 Jan 2005 20:15:05



> say I have a flag (file) that I'm waiting for to change and - when it
> does - will carry out a series of actions. Currently I use ls() on
the
> flag and loop running ls() until flag changes - I simply diff the
> output of the two ls commands to determine when the flag has changed
> but feel this is kindof primitive, code example is as follows :-

> flag=`ls $remote_file`
> is_flag_present="false"

> while [ "$is_flag_present" != "true" ]; do
> new_flag=`ls $remote_file`
> if [ "$new_flag" != "$flag"]; then
> is_flag_present="true"
> fi
> done

> can anyone suggest a better way to test if a file changes timestamp
> (not size, file is only touched to indicate a change) or any in-built
> ksh test that would be more appropriate and better syntax than above
> code block

use the '-nt' option of the builtin test command of ksh.
e.g.,

cp -p "$remote_file" '/tmp/orig' # store the original timestamp
until [[ $remote_file -nt /tmp/orig ]]; do sleep 1; done
another method would be to use the make command.

 
 
 

is there built-in ksh functionality to check if file timestamp has changed

Post by Stephane CHAZELA » Wed, 26 Jan 2005 20:19:34


2005-01-25, 03:07(-08), Michael Vilain:
[...]

Quote:>> while [ "$is_flag_present" != "true" ]; do
>> new_flag=`ls $remote_file`
>> if [ "$new_flag" != "$flag"]; then
>> is_flag_present="true"
>> fi
>> done

>> can anyone suggest a better way to test if a file changes timestamp
>> (not size, file is only touched to indicate a change) or any in-built
>> ksh test that would be more appropriate and better syntax than above
>> code block

> Do you have the GNU coreutils installed?  Or does your system have
> "stat"?  The stat utility can give you file information like ctime,
> mtime, or atime and a bunch of other things.  ksh only offers ls, which
> you then have to parse.

Not only,

ksh has [[ file1 -nt file2 ]]

ksh93 has [[ -N file ]]

but that's not necessarily useful to the OP.

zsh has a "stat" builtin and has a ksh emulation mode.

--
Stphane

 
 
 

is there built-in ksh functionality to check if file timestamp has changed

Post by Stephane CHAZELA » Wed, 26 Jan 2005 20:26:01


2005-01-25, 03:15(-08), Rakesh Sharma:
[...]
Quote:> use the '-nt' option of the builtin test command of ksh.
> e.g.,

> cp -p "$remote_file" '/tmp/orig' # store the original timestamp

[...]

Use touch -r instead, you don't need to duplicate the content of
"$remote_file" (which may not be a regular file, BTW).

--
Stphane

 
 
 

is there built-in ksh functionality to check if file timestamp has changed

Post by Dan Merce » Wed, 26 Jan 2005 22:48:00


: say I have a flag (file) that I'm waiting for to change and - when it
: does - will carry out a series of actions. Currently I use ls() on the
: flag and loop running ls() until flag changes - I simply diff the
: output of the two ls commands to determine when the flag has changed
: but feel this is kindof primitive, code example is as follows :-
:
: flag=`ls $remote_file`
: is_flag_present="false"
:
: while [ "$is_flag_present" != "true" ]; do
: new_flag=`ls $remote_file`
: if [ "$new_flag" != "$flag"]; then
: is_flag_present="true"
: fi
: done
:
: can anyone suggest a better way to test if a file changes timestamp
: (not size, file is only touched to indicate a change) or any in-built
: ksh test that would be more appropriate and better syntax than above
: code block
:

flag_file=/path/to/flag
cmp_file=/tmp/cmp_file
touch -r $flag_file $cmp_file

until [[ $flag_file -nt $cmp_file ]]
    do
    sleep 1
    done

Dan Mercer

 
 
 

1. What's 'side effects' of Ksh built-ins?

Hi,

I have a book called "The new KornShell Command and Programming
Language". In several chapters, it mentions "side effects" of
built-ins. I'm confused what's that so that I can't understand some
paragraphs. Any help is appreciated.

Lesley Yang

2. O_SYNC ceased to work on /dev/fd0

3. I am having a problem with sort on a solaris 2.6 box using ksh

4. Shutdown -- bug?

5. Compare file modification date using tcsh built-ins

6. Where can I hire someone

7. ksh history file timestamp

8. sls message: You don't exist, Go Away

9. Any way to timestamp ksh .sh_history file entries?

10. get timestamp of file in KSH

11. dir timestamps vs dir/file timestamps

12. How to change the timestamp of a files?