LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Ubuntu is creating files that are modified in future (https://www.linuxquestions.org/questions/linux-newbie-8/ubuntu-is-creating-files-that-are-modified-in-future-774667/)

ExWizzard 12-10-2009 02:05 AM

Ubuntu is creating files that are modified in future
 
This is a big problem for me , it happens when i torrent stuff and use auto extract from rar. For some certain files it will say that they are modified at 2098-01-01 00:00 which is bad for me.
Im looking for a way to touch those files , is there an equivalent for the find command like "ls -l |grep 2098" ? Or what do you guys suggest , find command fails to find future modified files and i have no idea how to touch them otherwise

catkin 12-10-2009 02:58 AM

Two issues: why is it happening and how to workaround the problem.

Re the first, what is you torrent program?

Re the second (quick and dirty, not tested)
Code:

while read x x x x x x x f8 fn
do
    if [[ "$f8" = '2098' ]]; then
        echo touch "$fn"
    fi
done <<< "$ls -l | grep '2098' )"


ExWizzard 12-10-2009 03:38 AM

Thanks for the reply , the torrent program is rTorrent 0.8.5/0.12.5
How do i run the script tho? I did save it as script.sh and did ./script.sh but nothing happens

linuxlover.chaitanya 12-10-2009 06:26 AM

You will need to add "x" to the permissions to allow it to be executed.

From the folder that contains the script file:

chmod +x script.sh

bartonski 12-10-2009 06:37 AM

Quote:

Originally Posted by catkin (Post 3786359)
Two issues: why is it happening and how to workaround the problem.

Re the first, what is you torrent program?

Re the second (quick and dirty, not tested)
Code:

while read x x x x x x x f8 fn
do
    if [[ "$f8" = '2098' ]]; then
        echo touch "$fn"
    fi
done <<< "$ls -l | grep '2098' )"


one quick and dirty, not tested, idea deserves another:

Code:

touch -t 209712312359.59 /tmp/foo
find . -newer /tmp/foo | xargs touch


catkin 12-10-2009 06:49 AM

Quote:

Originally Posted by ExWizzard (Post 3786393)
Thanks for the reply , the torrent program is rTorrent 0.8.5/0.12.5
How do i run the script tho? I did save it as script.sh and did ./script.sh but nothing happens

On further reflection it is probably not the torrent program that is causing the problem -- it simply downloads the files as uploaded -- but the files themselves or the program used to unrar them.

Oh, sorry I did not realise you are new to running scripts. The full script should be
Code:

#!/bin/bash

while read x x x x x x x f8 fn
do
    if [[ "$f8" = '2098' ]]; then  # In case some field other than modification time matched 2098
        echo touch "$fn"  # Remove echo when confident script is finding the right files
    fi
done <<< "$ls -l | grep '2098' )"

Then make it executable and run it
Code:

chmod 754 script.sh
./script.sh


bartonski 12-10-2009 07:06 AM

sometimes I do my best thinking in the shower...
 
Quote:

Originally Posted by bartonski (Post 3786578)
one quick and dirty, not tested, idea deserves another:

Code:

touch -t 209712312359.59 /tmp/foo
find . -newer /tmp/foo | xargs touch


This won't work on a 32 bit machine, due to the 2038 bug.

this works:

Code:

$ touch -t 203701010000.00 /tmp/foo; ls -l /tmp/foo
-rw-r--r-- 1 tiger tiger 80 2037-01-01 00:00 /tmp/foo

this doesn't:

Code:

$ touch -t 203901010000.00 /tmp/foo
touch: invalid date format `203901010000.00'

When I first thought about this, my first thought was that if you touch a file beyond the end of the epoch in 2038, the time might wrap around past 0, which would cause horrible problems with my code above (i.e. if you ran it in the root of your file system, you might end up touching a whole bunch of files... that's the kind of thing that makes my stomach tie up in a knot). The author of touch anticipated this, and won't let that happen.

Let that be a lesson to all those who run code by people who say "This is quick and dirty, I haven't tried it yet...". Try it in a sandbox first.

catkin 12-10-2009 07:15 AM

Quote:

Originally Posted by bartonski (Post 3786578)
one quick and dirty, not tested, idea deserves another:

Code:

touch -t 209712312359.59 /tmp/foo
find . -newer /tmp/foo | xargs touch


MMC :)

I tried that (actually touch --date <date>) on Slackware 13.0 32-bit and got an error message
Code:

c:~/d/tmp$ touch -t 209712312359.59 foo
touch: invalid date format `209712312359.59'
c:~/d/tmp$ touch -t 200712312359.59 foo
c:~/d/tmp$ ls -l foo
-rw-r--r-- 1 c users 0 Dec 31  2007 foo

Experimenting further it seems the touch command uses signed 32 bit integers to store timestamps thus the last time it can handle (seconds since 1 Jan 1970) is 22:14:07 on 18 Jan 2038. Presumably the inodes on ExWizzard's system can handle later times.

@ExWizzard: what is your distro and which file system type are you using (df -T will show)?

EDIT: did not see bartonski's post before posting this :cool:

ExWizzard 12-10-2009 08:23 AM

im using ext3 and its 64bit ubuntu
I did what you said with the script and when i run it i still dont get any feedback in terminal , did i miss something?

bartonski 12-10-2009 12:27 PM

Quote:

Originally Posted by ExWizzard (Post 3786700)
im using ext3 and its 64bit ubuntu
I did what you said with the script and when i run it i still dont get any feedback in terminal , did i miss something?

In catkin's script

Code:

#!/bin/bash

while read x x x x x x x f8 fn
do
    if [[ "$f8" = '2098' ]]; then  # In case some field other than modification time matched 2098
        echo touch "$fn"  # Remove echo when confident script is finding the right files
    fi
done <<< "$ls -l | grep '2098' )"

If you removed the "echo" in the statement
Code:

echo touch "$fn"
You shouldn't see anything whatsoever... it will quietly run touch on all of the files that have a date of 2098... theoretically. The echo statement is in there so that you can see which files match, before you go changing any dates.

If you haven't removed the 'echo' statement, and you're still not seeing anything, the run
Code:

ls -l
in the directory containing the future file or files, and we can troubleshoot catkin's script.

Alternatively, you can run

Code:

touch -t 209712312359.59 /tmp/foo
find . -newer /tmp/foo -print

This should give you a list of all of the files older than December 31, 2097. If this gives you the correct set of files, you can pipe that through "xargs touch".

catkin 12-10-2009 12:56 PM

Quote:

Originally Posted by ExWizzard (Post 3786700)
im using ext3 and its 64bit ubuntu
I did what you said with the script and when i run it i still dont get any feedback in terminal , did i miss something?

Are you, having a 64-bit distro, able to run this command without getting an error message?
Code:

touch -t 209712312359.59 /tmp/foo
Please post your ls -l output as bartonski suggested so we can see why the script didn't work.

BTW, there's a left parenthesis missing in the script (so it should have produced a syntax error ...?)
Code:

done <<< "$( ls -l | grep '2098' )"

ExWizzard 12-10-2009 03:10 PM

Quote:

Originally Posted by catkin (Post 3786926)
Are you, having a 64-bit distro, able to run this command without getting an error message?
Code:

touch -t 209712312359.59 /tmp/foo

works fine
Quote:

Please post your ls -l output as bartonski suggested so we can see why the script didn't work.
ls -l |grep 2098
-rw-r--r-- 1 x admin 781797409 2098-01-01 00:00
x
-rw-r--r-- 1 x admin 1564905860 2098-01-01 00:00
x
-rw-r--r-- 1 x admin 1565044656 2098-01-01 00:00
x
-rw-r--r-- 1 x admin 1565077502 2098-01-01 00:00
x
-rw-r--r-- 1 x admin 781956610 2098-01-01 00:00
x
-rw-r--r-- 1 x admin 1564542665 2098-01-01 00:00
x
-rw-r--r-- 1 x admin 1564853542 2098-01-01 00:00
x
-rw-r--r-- 1 x admin 1564382112 2098-01-01 00:00
x
Quote:

BTW, there's a left parenthesis missing in the script (so it should have produced a syntax error ...?)
Code:

done <<< "$( ls -l | grep '2098' )"

Didnt get a error but still same when i added it , and i tried without echo as well , does not work

Quote:

Alternatively, you can run

Code:

touch -t 209712312359.59 /tmp/foo
find . -newer /tmp/foo -print

This should give you a list of all of the files older than December 31, 2097. If this gives you the correct set of files, you can pipe that through "xargs touch".
Yes , this gives me the correct set of files]

catkin 12-11-2009 01:19 AM

Quote:

Originally Posted by ExWizzard (Post 3787019)
works fine

A good reason to migrate to 64-bit -- before 2037! Perhaps the rogue modified time timestamps are caused by the rar files being created on 32-bit systems. If you would like to post the torrent link I'll test on a 32-bit system.

Quote:

Originally Posted by ExWizzard (Post 3787019)
ls -l |grep 2098
-rw-r--r-- 1 x admin 781797409 2098-01-01 00:00
x
[snip]

Ah -- the one time I'm not pedantic about parsing ls output and using the stat command to get file data it backfires on me! The script is not working because the ls -l output fields are different. Here's from Slackware 13.0
Code:

c:~/d$ ls -ld Shell\ Folders/
drwxr-xr-x 7 c 1000 4096 Jun 26  2008 Shell Folders/

Quote:

Originally Posted by ExWizzard (Post 3787019)
Yes , this gives me the correct set of files]

Glad you got it sorted.

ExWizzard 12-11-2009 02:15 AM

Yeah thanks for the help all , should be working now.

bartonski 12-11-2009 10:57 AM

Your find command should work.

In terms of executing this in a cron job, I believe that I would put this in a script. I'm actually going to leave the details to you, because you seem to have a fairly firm grasp on all of the commands involved, and you'll definitely learn more by doing putting all the puzzle pieces together yourself. I forsee a couple of minor gotchas, and I want to see how you handle them. If you end up banging your head against this for more than a couple of hours, post specific questions, and I'll be happy to help.

If you do get it working, please post the results.


All times are GMT -5. The time now is 12:59 AM.