Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

Date change on files

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
new_perl_user
Asked:
new_perl_user
  • 4
  • 3
  • 2
1 Solution
 
sdernCommented:
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
 
new_perl_userAuthor Commented:
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
 
sdernCommented:
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
Independent Software Vendors: 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!

 
new_perl_userAuthor Commented:
Hi,
 Thank you for the reply. But I  want to do it  using shell not perl . Because my above script is in shell.
0
 
sdernCommented:
ls -l -rt | tail -1
0
 
point_pleasantCommented:
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
 
new_perl_userAuthor Commented:
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
 
point_pleasantCommented:
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
 
new_perl_userAuthor Commented:

Thank you the above code worked.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now