Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Running on a Solaris system.
I tried using the 'utime' command in Perl and it didn't work.
From the UNIX console I did touch -m 0515173398 logfile.xxx to change the date to Sun 17 May 1998 05:33:00 PM and this works fine. (Just to be sure I understand the touch command.)

In Perl:
 system("touch","logfile.xxx"); This works and sets the modification date and time to the current date/time.

However when I add parameters:
 system("touch","-m","0515173398","logfile.xxx");
to specify the modification date and the date/time, I get a message in the error.log. The message reads:
touch: cannot change times on logfile.xxx

How can I get this command to work with the parameters?

Any suggestions/help would be much appreciatiated. Thanks
Don.

PS. My ultimate goal is to use variables as in:

system("touch","-m","$datetime","$filename");

Replies are listed 'Best First'.
(tye)Re: Changing file modification date.
by tye (Sage) on Jan 09, 2002 at 01:44 UTC

    touch: cannot change times on logfile.xxx
    I'd hope that your touch program wasn't so broken as to not report errno. I'd expect to see something like:
    touch: cannot change times on logfile.xxx; Permission denied

    And I note that one reply here also suffers from this pet peeve of mine. If you write your attempt at using utime correctly to include:     utime( ... )  or  die "... $!\n"; then you'll see why it failed.

    I suspect there is more difference between the "working" and "not working" cases than what you described. Specifically, I suspect that your "working" cases were not via a CGI script but that your "not working" cases were done via CGI.

    So I suspect that the problem isn't that utime doesn't work, but instead that your CGI scripts don't have permission to modify the file in question.

    Again, this is mostly guesses.

            - tye (but my friends call me "Tye")
Re: Changing file modification date.
by belg4mit (Prior) on Jan 09, 2002 at 00:46 UTC
    Where is your code using utime? Other than the odd syntax I've never had any problems with it...

    --
    perl -pe "s/\b;([st])/'\1/mg"

Re: Changing file modification date.
by belg4mit (Prior) on Jan 09, 2002 at 01:17 UTC
    Also, there is no need to quote your variables in this case. "abc$def" is meaningful because you're interpolating and it amounts to a concatenation. "$def" eq $def; well perhaps unless $def is some dual value variable.

    --
    perl -pe "s/\b;([st])/'\1/mg"

Re: Changing file modification date.
by metadoktor (Hermit) on Jan 09, 2002 at 01:42 UTC
    Assuming that you have no typos, you might have a permissions and/or PATH problem. When you execute this script is it in the same directory as "logfile.xxx"? Also you may want to try this statement to eliminate any path problems.

    print `/usr/bin/touch -m 0515173398 /path-to-file/logfile.xxx`;
    

    metadoktor

    "The doktor is in."

Re: Changing file modification date.
by grep (Monsignor) on Jan 09, 2002 at 00:51 UTC
     perl -e 'utime("0515171398","0515171398","test.pl")' seems to work for my on my RH7 box. I would check your syntax and permissions.

    -rwx------    1 cbrink   cbrink        139 Apr 29  1986 test.pl

    HTH

    grep
    grep> cd pub grep> more beer