Solved

Date change on files

Posted on 2011-03-25
9
396 Views
Last Modified: 2012-05-11
Hi,
 Through shell script I am calling a perl script and once the script is executed, I am changing the permissions on certain folders and also converting the output file to dos format for user readability.

But this is changing the old files too. I mean for example if some files were created yesterday they have that date and timestamps.  But when the script runs today it is changing their date to today's date.

So is there a way we could do based on date and time. by the way this script runs everyday at 6 through cron.

#!/bin/sh
. /usr/nlm/qa/.profile

/usr/nlm/qatest/Scripts/info.pl

chmod -R 755 /usr/qatest/data/manifests/*

chmod -R 755 /usr/qatest/data/output/*

unix2dos /usr/qatest/data/manifests/*
0
Comment
Question by:new_perl_user
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 2

Expert Comment

by:sdern
ID: 35217744
So what you're trying to do is change permissions on folders + subfolders and files, based on their timestamp?

Or are you trying to change the access permissions without changing the date?
If that is the case what you could try to do is read the date, do the file change permissions then change the date back to what you just read. I can't find any flags in chmod that will leave the date alone and just change the permissions.

touch is the command for changing the time
0
 

Author Comment

by:new_perl_user
ID: 35217823
ok what I am trying to do was. when the script runs it creates a log files under "/usr/qatest/data/manifests" . so once the log file is created I am tring to change the permissions on it and then convert it to dos format .

But issue is .  It is performing the same action on previously generated log files also.

I mean it is changing today and even the old ones.  So the date on all the files are being updated always.

This is happening because I am declaring  chmod -R 755 /usr/qatest/data/manifests/* .  It is working on all the files.

so can ayone tell me how to restrict it by date.
0
 
LVL 2

Expert Comment

by:sdern
ID: 35217873
So generating log files is fine. You just want to change the permissions on the latest log file.
You can try using the find command and look for the latest date.

Here is a post regarding your question

http://www.codingforums.com/showthread.php?t=131078

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:new_perl_user
ID: 35218029
Hi,
 Thank you for the reply. But I  want to do it  using shell not perl . Because my above script is in shell.
0
 
LVL 2

Expert Comment

by:sdern
ID: 35218148
ls -l -rt | tail -1
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35258088
using the chmod ..../* will by default change everything in the directory
you need to identify todays file
try this



#!/bin/sh
. /usr/nlm/qa/.profile

/usr/nlm/qatest/Scripts/info.pl

todays_file=` ls -ltr | awk '{print $9}' | tail -1`

chmod -R 755 /usr/qatest/data/manifests/$todays_file

chmod -R 755 /usr/qatest/data/output/$todays_file

unix2dos /usr/qatest/data/manifests/$todays_file
0
 

Author Comment

by:new_perl_user
ID: 35259553
Hi,
 How does the above code work. Because when I tried it , it is picking up the newest files from the path where the script runs and trying to append it in $today's file.

I have a bunch of scripts at  /usr/nlm/qatest/Scripts
and I am running the above script as  /usr/nlm/qatest/Scripts/info1.pl

so  the code is becoming then:

chmod -R 755 /usr/qatest/data/manifests/test.pl

chmod -R 755 /usr/qatest/data/output/test.pl

unix2dos /usr/qatest/data/manifests/test.pl


where test.pl is the script which has been modified recently at /usr/nlm/qatest/Scripts
0
 
LVL 8

Accepted Solution

by:
point_pleasant earned 500 total points
ID: 35260535
what the script does is set $today_file to the newest file in the directory the ls -ltr gives listing in reverse order the tail -1 takes the last one listed i.e. the newest pipes to awk to get the file name.  that filename is the handed to chmod.

the call should be run in the target directory i.e.

todays_file=` ls -ltr /usr/qatest/data/manifests | awk '{print $9}' | tail -1`

so

#!/bin/sh
. /usr/nlm/qa/.profile

/usr/nlm/qatest/Scripts/info.pl

todays_file=` ls -ltr /usr/qatest/data/manifests | awk '{print $9}' | tail -1`
chmod -R 755 /usr/qatest/data/manifests/$todays_file

todays_file=` ls -ltr /usr/qatest/data/outputs | awk '{print $9}' | tail -1`
chmod -R 755 /usr/qatest/data/output/$todays_file

todays_file=` ls -ltr /usr/qatest/data/manifests | awk '{print $9}' | tail -1`
unix2dos /usr/qatest/data/manifests/$todays_file
0
 

Author Comment

by:new_perl_user
ID: 35261925

Thank you the above code worked.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question