Solved

Date change on files

Posted on 2011-03-25
9
369 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now