LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2009, 05:49 PM   #1
mac-mark
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Rep: Reputation: 0
Script to check for and replace files?


Hi I'm pretty new to scripting but I'm trying to write a script that will look for new files, and if it finds files that haven;t been updated I want the script to replace all non-updated files to a specific file. To clarify, I have a scheduler set up to run 20 reports on a monthly basis, the output from these reports are then sent to a directory on our webserver so that they can be viewed online. I am currently overwriting the files on the weberver each month with updated reports of the same name to display updated content. I want to completely automate the process, but the problem is that some months there may only be 15 new reports so I have to manually change the path to indicate that there are no new reports for the other 5 for that month. I'm hoping that it's possible to write some kind of Perl or Bash script that will look for updated files in a directory on a given date, and if one or more of the report files has not been updated (overwritten) it will change the file path to display a no new report for this month message. Of course I can see potential problem with this because when the next monthly report is ran and the files are automatically transferred to the webserver directory they will not overwrite the the files that are pointing to the 'no new report message' from the previous month. I hope this makes some sense to someone, I'm having trouble figuring out where to start, but the more I think about it the more complicated it gets.

Last edited by mac-mark; 03-21-2009 at 05:52 PM.
 
Old 03-21-2009, 06:05 PM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
man find -ctime

check the timestamp on the file, though of course this doesn't guarantee they have
actually changed.

how about moving the files before the run?
then only new reports are found.

OR

archive the reports and truncate them to zero bytes.
then do the run.
then you can tell which reports are new.
 
Old 03-22-2009, 06:26 AM   #3
mac-mark
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for that bigearsbilly. Like I said I'm fairly new to scripting, I thought of -mtime to check file dates - I think that what I thought was going to be a simple process is actually quite complicated. Steps are: Reports are ran each month (these produce web page output), html files are then transferred over to our Linux box webserver to directory x, the new reports have the same name as existing files in the directory so existing ones are overwritten. I can then go to my webpage and click links to view each report page. What I have been doing manually is changing the path of files that have had no new data for that month to another html file, which shows the user a 'no new reports for this month' page. This is the part I'm having the issue with, I think I need some code that will tell the web browser to look for the requested file on the Linux webserver, but if that particular file hasn't been updated that month then to display the 'no new reports' page instead. Then next month when the files are overwritten there will not be any problems with paths that are pointing to 'no new reports' instead of a generic file name. Hopefully you can see what I'm getting at, I would have to manually go back in and edit the webpage code to point back at the generic file names each month. Maybe I need to rethink that whole setup, anyone know whether it's possible to do something like this with SQL?? Any help or tips greatly appreciated.

Last edited by mac-mark; 03-22-2009 at 06:28 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to check how many files in directory guest Programming 8 01-31-2009 11:55 PM
how to replace value of 4.1.0.1.22 to 4.1.0.0.22 using shell script amit_pansuria Programming 3 08-06-2008 08:30 PM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 10:37 PM
find and replace script UnixKiwi Programming 12 04-16-2007 11:08 PM
Script file to replace large text blocks in files? stodge Linux - Software 0 09-27-2003 10:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration