touch

why am i unable to change the timestamp on a file

I'm getting the following error on AIX.
touch: cannot change times

Any help is appreciated.

Regards,
Ram.

You will need file write permissions to change the date.

I don't think you actually need to own the file (user ID match), but you have to have the right permissions.

I have the permissions to write....
here is the scenario.
I have a shell script which monitors a particular directory for text files, If found it processes the files sequentially (fifo)and uploads data into a database, this shell script is up and running all the time.(where 1=1)
but, some files in this directory have dependency on other files, say I should have two text files to kick the process to upload the data from them into a database.
For some reason if the shell script sees only one file among the two it will not process it until it sees its dependecy (other missing)file in the directory
so as to give preference to the files other than this dependency set , I have added a touch command ( the whole purpose of this is to change the time stamp) and make the fifo logic work out.
but strangely the system is throwing the above error. This functionality was working fine for the last few months
Any idea what might be triggering the system to throw this error..
Thanks for your attention and precious time.
Regards,
Ram

The touch command is built upon the utime()/utimes() system calls. So look up those system calls for your OS to see why they might fail. My copy of AIX 5.3 docs says:

EPERM
The Times parameter is not null and the calling process neither owns the file nor has root user authority.
EACCES
The Times parameter is null, effective user ID is neither the owner of the file nor has root authority, or write access is denied.
EROFS
The file system that contains the file is mounted read-only.

Hmmm, I hope that is an error in documentation or at least the docs are unclear. It is supposed to be like this...

The effective uid must own the file and have write permission to the file or the effective uid must be root. If the Times parameter is null, we are just seeing if we could change the times if we wanted to... but we will not actually change anything if we have permission. If it fails, you get EPERM or EACCES depending on whether or not you were trying to change anything.

But if you are not root, you must own the file. This is required by Posix.

The problem is 100% due to the permission. First the script would have run in some other user id, so that when u tried to execute the script the touch command couldn't able to change the time stamp as the file has no write permission.

For eg, when first tried with someother id the file woul have created with rw-r--r-- permission. While u tried with some other id without deleting the file which was created earlier it would have thrown the error as u have mentioned.