One liner for cron - modified files

Need a one liner cron entry on SunOS box to list modified files from a certain path every 5 mins out to a log file.
Here's what I have that works in Linux....

find /path/to/files -type f -newerct '10 minutes ago' -exec ls -lat {} \; >> /path/to/logfile
cipherlogicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nemws1Database AdministratorCommented:
The version of find on SunOs is usually pretty old.  You can install GNU's version of find and use your above command, or put this is a script and call the script from cron:

#!/usr/bin/ksh
a=$( /usr/bin/date "+%Y%m%d%H%M" )
a=$(( $a - 10 ))
/usr/bin/touch -t $a /tmp/dummy
/usr/bin/find /path/to/files -newer /tmp/dummy1 -exec ls -lat {} \; >>/path/to/logfile

Open in new window


You can actually put this all in one line, but its messy:
a=$( /usr/bin/date "+%Y%m%d%H%M" ) && a=$(( $a - 10 )) && /usr/bin/touch -t $a /tmp/dummy && /usr/bin/find /path/to/files -newer /tmp/dummy1 -exec ls -lat {} \; >>/path/to/logfile

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cipherlogicAuthor Commented:
Excellent, thanks!
0
cipherlogicAuthor Commented:
Nice solution, information and options!
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

cipherlogicAuthor Commented:
Could you take a look at the date conversion part?
I'm seeing dates like Jan 18 2038...not sure how to fix it.
0
nemws1Database AdministratorCommented:
What do you get when you just run this on the command line:

/usr/bin/date "+%Y%m%d%H%M"

Open in new window


Also, what is your exact OS that you're running? Run this:

uname -a

Open in new window

0
cipherlogicAuthor Commented:
uname gives:
SunOS 5.10 Generic_147441-02 i86pc i386 i86pc

The date command yields:
201408130954
0
nemws1Database AdministratorCommented:
I get this from the above date command:
201408130956

Open in new window

Which is:
2014 - year
08 - month
13 - day
09 - hour
56 - minutes
0
nemws1Database AdministratorCommented:
OKay - that is 100% correct.

Run this and post the output (must be the math part, then)
a=$( /usr/bin/date "+%Y%m%d%H%M" )
echo $a
a=$(( $a - 10 ))
echo $a

Open in new window

0
cipherlogicAuthor Commented:
201408131917
201408131907
The problem seems to be when the script prints the date formatted to the screen.
I get:
-rw-r--r-- 1 userid group 4455233456 Jan 18 2038 /path/file.txt
0
cipherlogicAuthor Commented:
Also, you have a dummy and dummy1 file. I figured the dummy1 was a typo , so I changed it to just dummy.
0
cipherlogicAuthor Commented:
Just more info...
date command output....
Wed Aug 13 19:33:24 CDT 2014
0
cipherlogicAuthor Commented:
Oh weird. ...when I just run ls -lat on a file it returns the Jan 18 2038 date....
0
cipherlogicAuthor Commented:
Check out the dates here:

[1022] root@server # ls -lat
total 1132535
-rw-r--r--      1 uid  group   365421762     Jan  18  2038 nr.txt
drwxr-xr-x   2 uid  group    7                    Apr  28  2006 .
drwxr-xr-x   5 uid  group    5                    Oct  27  2004 ..
-rw-r--r--     1 uid  group    1076               Jun  1    2003 readme.txt
-rw-r--r--     1 uid  group    22251280       Nov  15  2002 jnrds.ai
-rw-r--r--     1 uid  group    138385           Jul   12  2002 schema.pdf
-rw-r--r--     1 uid  group    192043312     Dec  31  1969 nr.z
0
nemws1Database AdministratorCommented:
Yes, my mistake on 'dummy1' vs 'dummy' - should be the same.  The math from the example I had you run is perfect - it prints out the date minus 10 mins.  What's the output from:

/usr/bin/touch -?

(Should give usage information - I'm interested in the '-t' option)
0
cipherlogicAuthor Commented:
You'll see further down what the issue is.
0
nemws1Database AdministratorCommented:
I think the wrong value is somehow being sent to to touch - which is why I was asking for what your 'touch' command wants.  I'm running Solaris 5.10 on x86 as well and its working for me. :(
0
cipherlogicAuthor Commented:
It's my actual dates. I mentioned above. I have files from the future somehow. Like from 2038...some from the past in 1969...very odd.
0
cipherlogicAuthor Commented:
I think I'm understanding what you mean now. I looked into touch and sometimes can make odd changes to time and date.

Here's what I get with /usr/bin/touch -?

# /usr/bin/touch -?
/usr/bin/touch: illegal option -- ?
usage: touch [-acm] [-r ref_file] file...
       touch [-acm] [-t [[CC]YY]MMDDhhmm[.SS]] file...
       touch [-acm] [-d YYYY-MM-DDThh:mm:SS[.frac][Z]] file...
       touch [-acm] [-d YYYY-MM-DDThh:mm:SS[,frac][Z]] file...
       touch [-acm] [MMDDhhmm[yy]] file...
0
cipherlogicAuthor Commented:
-t time

         Uses the specified time instead  of  the  current  time.
         time will be a decimal number of the form:

           [[CC]YY]MMDDhhmm[.SS]

         where each two digits represent the following:

         MM

             The month of the year [01-12].

         DD

             The day of the month [01-31].

         hh

             The hour of the day [00-23].

         mm

             The minute of the hour [00-59].

         CC

             The first two digits of the year.

SunOS 5.10           Last change: 9 Sep 2008
0
nemws1Database AdministratorCommented:
You have a newer version of touch than I do, but the format is still the same for "-t", so the script I wrote up should work.  Not quite understanding what you're still getting such weird times. :(

The dates of 1969 and 2038 are actually *common* to see in UNIX.  Those are a datestamp of 0 (Jan 1, 1969) and the a datestamp of 2^32 (2038).  So either you are passing a 0 or a really big number to get dates of those times.
0
cipherlogicAuthor Commented:
Just a note:
Not all file dates have been changed in my path I ran the script on. Hundreds yes, but that's only a few by comparison.
0
cipherlogicAuthor Commented:
Any idea how they were set that way? Could the script have done this?
0
cipherlogicAuthor Commented:
I think your script caused my file dates to change using touch. Please acknowledge and if possible fix this issue in the script.
0
nemws1Database AdministratorCommented:
If you ran my script, then no.  It should only have changed the modification time of the '/tmp/dummy' file.

I assumed you had taken my script and modified it to do other things.  Correct or not?
0
nemws1Database AdministratorCommented:
Again, you'll see file times like these often.  I've seen them when extracting ZIP/RAR files, etc.
0
cipherlogicAuthor Commented:
I only ran the code as you provided with he exception of changing path info and rectifying your typo.
0
nemws1Database AdministratorCommented:
Then my script did *not* change the file times on those files.
0
cipherlogicAuthor Commented:
Then I should see other files not in this path with similar dates.
Let me see...
0
cipherlogicAuthor Commented:
What I don't understand, if you code didn't make these modifications, why is it that the only things returned in the logfile entries of files with these wrong dates? 2020, 2037, 2038, Dec 1969, etc...
0
cipherlogicAuthor Commented:
You're right, there are other files on the machine with these odd dates. So I stand corrected.

But please, answer this:
What I don't understand, if you code didn't make these modifications, why is it that the only things returned in the logfile entries of files with these wrong dates? 2020, 2037, 2038, Dec 1969, etc...

Also, how can I just get the new find command installed on this old ass sun box? So it's more like a modern Linux box...
0
cipherlogicAuthor Commented:
I think your code logs these date anomalies, or outliers, by accident.

Any idea how to get this legacy systems find command up-to-date?
0
nemws1Database AdministratorCommented:
Yes, I was just thinking, how often do you search for files in the future? It's not something you normally do.  My script will print out all files from 10 minutes ago to anytime in the future.

You can simply 'touch' those offending files and their modification day will switch to "now" and in 10 minutes the script will start working correctly.

Do you have the SunOS development environment installed?  If so, compiling and installing the GNU 'fileutils' package should be pretty easily to compile and install.  It used to be that many of these packages were free to download and install as SunOS installation packages, but I think that's no longer the case.
0
cipherlogicAuthor Commented:
Thanks for the extra work here.
Double points for this guy!
0
nemws1Database AdministratorCommented:
No problem. :)
0
cipherlogicAuthor Commented:
One last bother, if you will. But how can I modify your code to touch the files its finding as outliers. I'd then run it once and switch back to the monitoring code.
0
nemws1Database AdministratorCommented:
We'll use find again, just modified a little bit.  Assuming all offending dates are *files* and not directories:

find /path/to/dir -type f -exec touch "{}" \;

Open in new window

0
cipherlogicAuthor Commented:
Excellent!
Thanks....
0
cipherlogicAuthor Commented:
That would touch all files in the path wouldn't it? I just want to touch the ones your script pops out that are outlier dates.
0
cipherlogicAuthor Commented:
I substituted touch for the ls portion of the end of the one liner...

a=$( /usr/bin/date "+%Y%m%d%H%M" ) && a=$(( $a - 10 )) && /usr/bin/touch -t $a /tmp/dummy && /usr/bin/find /path/to/files -newer /tmp/dummy -exec touch {} \; >>/path/to/logfile
0
nemws1Database AdministratorCommented:
Derp.  Very stupid of me.  This will create a dummy file (/tmp/now) and then find anything newer than it and touch just those files.
touch /tmp/now
/usr/bin/find /path/to/files -newer /tmp/now -type f -exec touch "{}" \;
rm /tmp/now

Open in new window

0
nemws1Database AdministratorCommented:
Yup - you're version will essentially work, only that it updated anything from 10 minutes ago to anything in the future.  If you ran than, in 10 mins the original script should do exactly what you want. :)
0
cipherlogicAuthor Commented:
Cool - thanks!
0
cipherlogicAuthor Commented:
Now I'll run the original script to track changes. This is for a project keeping time with changes in files associated to the sounds produced by the cpu. I mostly needed things as they are or normalized. Now I'll be able to accurately record the changes and track them.

Best!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.