1846620 Members
1582 Online
110256 Solutions
New Discussion

Script question

 
Prashant Zanwar_2
Occasional Advisor

Script question

Hi,

I want to compare the files date with current date of the system. How to do it in a script.

Please reply.

Thanks and regards
Prashant

7 REPLIES 7
RAC_1
Honored Contributor

Re: Script question

ll|awk '{print $6,$7} will give you dates stamp of a file. Not date "+format youwant" will give you date as you want. With these two things you should be bale to compare the file dates.

Also when comparing, you can use find . -newer option also. Man find for details.
There is no substitute to HARDWORK
H.Merijn Brand (procura
Honored Contributor

Re: Script question

Which scripting language? sh, csh, awk, sed, perl, ...

Please check out A.Clay's date hammer from https://www.beepz.com/personal/merijn/#Contrib

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Mark Grant
Honored Contributor

Re: Script question

Well short oof using "find" with the -mtime switch, you could use perl. Not exactly sure what you mean by "compare" but this line of perl will give you the modification time of the file. You can compare this with the output of the perl "time" function in which ever way you want.

perl -e 'print map { (stat $_)[9] } glob "filename"

p.s Thanks Merijn for the "map" lesson :)
Never preceed any demonstration with anything more predictive than "watch this"
H.Merijn Brand (procura
Honored Contributor

Re: Script question

wheely, that is missing quotes. And comparing to system date (or date script started), better be done with

# perl 'print map { -M } map { glob $_ } @ARGV' file ...

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Prashant Zanwar_2
Occasional Advisor

Re: Script question

I want to do it using KSH and awk, I want to see if file is older than these many days to current date, I want to compress or delete the file.
Actual shell script would be helpful.

Thanks for all responses, I will assign points..
Thanks
Regards
Prashant
Elmar P. Kolkman
Honored Contributor

Re: Script question

The command your looking for is:

find -type f -mtime + -exec gzip {} \;

This will gzip files older then the number of days specified.
Every problem has at least one solution. Only some solutions are harder to find.
Mark Grant
Honored Contributor

Re: Script question

Merijn,

I see I still need more lessons :)
Never preceed any demonstration with anything more predictive than "watch this"