Check the modification date of a file and compare it to the current date

Hey everyone,
I'm writing a script that compares the modification date of a file to the current date, and performs actions based on whether the file was modified 7 days ago or not. I haven't been able to figure out exactly how to do this.
I haven't been able to find much in the way of this online, and I am not that familiar with manipulating dates and whatnot. I was able to get a bit of it, posted below:
currentDate=`date +%b-%d`
fileDate=`ls -l ~/.backup.txt | awk '{ print $6, $7 }'`
echo "$fileDate"
echo "$currentDate"
if [ "$fileDate" <= "$currentDate" ]; then
echo "old enough to run script"
else
echo "not old enough yet"
fi
Of course, this doesn't work. Any help would be much appreciated. This is for Leopard.
TIA,
Andrew

find ~/.backup.txt -mtime +7 -exec yourscript {} ;
You may need to play with the +7 value to get the exact number of days old the file needs to be.
The find command will accept a directory (actually it is frequently used with directories) and will find all files in that directory and any subdirectories below that match the find selection critiera.
So you could do something like
find ~ -mtime +7 | xargs yourscript
or
find ~ -mtime +7 -name "*.txt" | xargs yourscript
and if your script does not accept multiple filenames on the command line, you can use
find ~ -mtime +7 | xargs -n 1 yourscript
and if your file names have spaces in them, you can use
find ~ -mtime +7 -print0 | xargs -0 -n 1 yourscript

Similar Messages

  • Reading the data from 2 files and writing it into the 3rd file?

    Hi,
    I am reading datas from 2 files Say,
    Example1.txt Example2.txt
    Ashok ^data1^data2^data3
    Babu ^data1^data2^data3
    Chenthil ^data1^data2^data3
    Danny ^data1^data2^data3
    I want those data's to be written in a 3rd file. Say,
    Example3.txt
    Ashok^ data1^data2^data3
    Babu^ data1^data2^data3
    Chenthil^ data1^data2^data3
    Danny^ data1^data2^data3
    So that i can tokenize it with a delimeter(^) and get the values. Here how to append the datas in this form in Example3.txt. Eventhough u use FileWriter with append "true" as a parameter how they will apend like the Example3.txt file? Please do provide an answer for this..Since this is very urgent to be delivered...Expecting postive response.
    Thanx,
    JavaCrazyLover

    import java.io.*;
    import java.util.*;
    public class en
    public static void main(String args[]) throws IOException     
    {int data,data1,offset,offset1;
              FileOutputStream fos1=new FileOutputStream("c:/example3.txt");
              FileInputStream fis=new FileInputStream("c:/example1.txt");
              FileInputStream fis1=new FileInputStream("c:/example2.txt");
    while((data=fis.read())!=-1) 
         fos1.write(data);
    while((data=fis1.read())!=-1) 
    fos1.write(data);
    fis.close();
    fis1.close();
    fos1.close();
    }first create those 3 files in c:

  • How to get data from pdf file and send contents  of the pdf file to R/3

    Hi, experts,
    Action:
    1. Make a pdf forms (interactive form) with inputfield named “A_inputfield” in the webdynpro application and run the webdynpro application.
    2. In the IE, click the save button in the pdf interactive form and save the pdf to local disk,ex: C disk. Close the IE browser.
    3. Open the pdf interactive form from the local C disk and type "aaa" to the “A_inputfield”.
    4. I want to save the "aaa" to the R/3 system using webdynpro or using other tools . How can I do it?
    First way:
    If I use webdynpro application to save the content of the pdf, I don't find a way mapping or binding the content to a context of a view. So I don't think this way is unadvisable.
    Second way:
    Adding a button "submit" in the pdf forms when create the pdf form. Runing the webdynpro application, save the pdf to local disk,ex: C disk.  Opening the pdf interactive form from the local c disk and typing "aaa" to the “A_inputfield”, click the  "submit" button to save the content. Of course, I need to finish the code for clicking "submit" button. But I don't know how  to write these codes and where to write these codes. Do you give me some advise ?
    Best regards,
    tao

    Hi, Abhimanyu L,
    Thanks a lot for your help. Your answer can give me large developmental.:)
    I find http://help.sap.com/saphelp_erp2005/helpdata/en/67/fae9421dd80121e10000000a155106/content through searching google for CL_WD_ADOBE_SERVICES class. But I don't find any exmples for the class. Do you give me some hint for some exmples for the class?
    Best regards,
    tao
    (You can reply back to me via e-mail if you think we should discuss this internally at [email protected] or [email protected])

  • I can't get my Windows 7 pc to recognise my old LG VN251 phone via USB.   The verison software upgrade assistant runs and my phone is up to date.   I do get a window that pops up that says I can either run the bootstrap or look at the files on the phone,

    I can't get my Windows 7 pc to recognise my old LG VN251 phone via USB.   The verison software upgrade assistant runs and my phone is up to date.   I do get a window that pops up that says I can either run the bootstrap or look at the files on the phone, but I cannot see any photos.   Thoughts?

    We want to make sure we move your pictures to your computer schpee! Do you have a memory card on your phone? If your pictures are not on your http://vz.to/1OvJVey memory card we would want to move them. After you move them than try http://www.verizonwireless.com/support/knowledge-base-45147/ to move them to your computer. Keep us posted.   AmberF_VZW Follow us on Twitter @VZWSupport If my response answered your question please click the "Correct Answer" button under my response. This ensures others can benefit from our conversation. Thanks in advance for your help with this!!

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • Hi i am new to labview. i want to extract data from a text file and display it on the front panel. how do i proceed??

    Hi i am new to labview
    I want to extract data from a text file and display it on the front panel.
    How do i proceed??
    I have attached a file for your brief idea...
    Attachments:
    extract.jpg ‏3797 KB

    RoopeshV wrote:
    Hi,
    The below code shows how to read from txt file and display in the perticular fields.
    Why have you used waveform?
    Regards,
    Roopesh
    There are so many things wrong with this VI, I'm not even sure where to start.
    Hard-coding paths that point to your user folder on the block diagram. What if somebody else tries to run it? They'll get an error. What if somebody tries to run this on Windows 7? They'll get an error. What if somebody tries to run this on a Mac or Linux? They'll get an error.
    Not using Read From Spreadsheet File.
    Use of local variables to populate an array.
    Cannot insert values into an empty array.
    What if there's a line missing from the text file? Now your data will not line up. Your case structure does handle this.
    Also, how does this answer the poster's question?

  • Reading data From XML file and setting into ViewObject to Pouplate ADF UI

    Hi,
    I have following requirement.
    I would like to read data from XML file and populate the data in ViewObject so that the data can be displayed in the ADF UI.
    Also when user modifies the data in the ADF UI, it should be modified back into to ViewObject.
    Here is an example - XML file contains Book Title and Author. I would like to read Book Title and Author from XML file and set it into ViewObject Attribute and then display Book title and Author in ADF UI page. Also when user modifies Book title and Author, I would like to store it back in View Object.
    Please help me with this requirement and let me know if any solution exist in ADF, for populating the ADF UI screen fields with external XML file data.
    Thanks

    Read chapter 42 http://download.oracle.com/docs/cd/E16162_01/web.1112/e16182/bcadvvo.htm of the fusion developer guide
    Section 42.7, "Reading and Writing XML"
    Section 42.8, "Using Programmatic View Objects for Alternative Data Sources"
    Timo

  • I can't seem to print to PDF from other programs.  I have Acrobat 9 (with latest update), Windows 8, and when I try to print to PDF it defaults to a  *.prn file, and when I change the name to *.pdf the file that it produces doesn't open.

    I can print to PDF using PDF995, but not the regular Adobe PDF that comes up in the list of printers.
    I've tried repairing the Adobe installation, but that didn't help.

    It might help to understand the process, though I am almost surprised that AA 9 worked for printing on Win 8 (thanks for that info). Normally the print process is to print to the Adobe PDF printer (without the print-to-file checked). The process does create a PRN file that is actually a PS file. AcroTray (running in the background) completes the process of taking the PS file and running Distiller in the background to create the PDF. If you have problems, you should be able to print to file (assuming the print driver works -- but you indicate it does) and then opening the PRN file in Distiller to create the PDF.

  • How can I input read a line from a file and output it into the screen?

    How can I input read a line from a file and output it into the screen?
    If I have a file contains html code and I only want the URL, for example, www24.brinkster.com how can I read that into the buffer and write the output into the screen that using Java?
    Any help will be appreciate!
    ======START FILE default.html ========
    <html>
    <body>
    <br><br>
    <center>
    <font size=4 face=arial color=#336699>
    <b>Welcome to a DerekTran's Website!</b><br>
    Underconstructions.... <br>
    </font> </center>
    <font size=3 face=arial color=black> <br>
    Hello,<br>
    <br>
    I've been using the PWS to run the website on NT workstation 4.0. It was working
    fine. <br>
    The URL should be as below: <br>
    http://127.0.0.1/index.htm or http://localhost/index.htm
    <p>And suddently, it stops working, it can't find the connection. I tried to figure
    out what's going on, but still <font color="#FF0000">NO CLUES</font>. Does anyone
    know what's going on? Please see the link for more.... I believe that I setup
    everything correctly and the bugs still flying in the server.... <br>
    Thank you for your help.</P>
    </font>
    <p><font size=3 face=arial color=black>PeerWebServer.doc
    <br>
    <p><font size=3 face=arial color=black>CannotFindServer.doc
    <br>
    <p><font size=3 face=arial color=black>HOSTS file is not found
    <br>
    <p><font size=3 face=arial color=black>LMHOSTS file
    <br>
    <p><font size=3 face=arial color=black>How to Setup PWS on NT
    <BR>
    <p><font size=3 face=arial color=black>Issdmin doc</BR>
    Please be patient while the document is download....</font>
    <font size=3 face=arial color=black><br>If you have any ideas please drop me a
    few words at [email protected] </font><br>
    <br>
    <br>
    </p>
    <p><!--#include file="Hits.asp"--> </p>
    </body>
    </html>
    ========= END OF FILE ===============

    Hi!
    This is a possible solution to your problem.
    import java.io.*;
    class AddressExtractor {
         public static void main(String args[]) throws IOException{
              //retrieve the commandline parameters
              String fileName = "default.html";
              if (args.length != 0)      fileName =args[0];
               else {
                   System.out.println("Usage : java AddressExtractor <htmlfile>");
                   System.exit(0);
              BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));
              StreamTokenizer st = new StreamTokenizer(in);
              st.lowerCaseMode(true);
              st.wordChars('/','/'); //include '/' chars as part of token
              st.wordChars(':',':'); //include ':' chars as part of token
              st.quoteChar('\"'); //set the " quote char
              int i;
              while (st.ttype != StreamTokenizer.TT_EOF) {
                   i = st.nextToken();
                   if (st.ttype == StreamTokenizer.TT_WORD) {          
                        if (st.sval.equals("href")) {               
                             i = st.nextToken(); //the next token (assumed) is the  '=' sign
                             i = st.nextToken(); //then after it is the href value.               
                             getURL(st.sval); //retrieve address
              in.close();
         static void getURL(String s) {     
              //Check string if it has http:// and truncate if it does
              if (s.indexOf("http://") >  -1) {
                   s = s.substring(s.indexOf("http://") + 7, s.length());
              //check if not mailto: do not print otherwise
              if (s.indexOf("mailto:") != -1) return;
              //printout anything after http:// and the next '/'
              //if no '/' then print all
                   if (s.indexOf('/') > -1) {
                        System.out.println(s.substring(0, s.indexOf('/')));
                   } else System.out.println(s);
    }Hope this helps. I used static methods instead of encapsulating everyting into a class.

  • How to Load the data from excel file(Extension is .CSV) into the temp.table

    Hi
    How to Load the data from excel file(Extension is .CSV) into the temporary table of oracle in Forms11g.
    My Forms Version is - Forms [64 Bit] Version 11.1.2.0.0 (Production)
    Kindly Suggest the Solution.
    Regards,
    Sachin

    Hello Sachin,
    You can use the following metalink note:How to Read Data from an EXCEL Spreadsheet into a Form Using Webutil Client_OLE2 (Doc ID 813535.1) and modify it a little bit.
    Instead of copy values into forms you can save them in your temporary table.
    Kind regards,
    Alex
    If someone's helpful or correct please mark it accordingly.

  • How do i make a still image (photo) fit the length of the music? I record music and want to put the tracks to a video file with a still image of my business logo in the background. Any help?

    How do I make a still image (photo) fit the length of the music? I record music and want to convert the tracks to a video file with a still image of my business logo in the background. On windows movie maker you could just select "fit to music" but this program isnt as easy to figure out! Any help?

    Double-click on the still image in the project timeline to open the Inspector. In the Inspector, adjust the duration by typing in a new duration to match the length of your music. I think the limit for a still image is 10 minutes. If you need more than this, simply drag the image into the timeline again then adjust its duration. The two images will play seamlessly (no gap will be visible).
    See this iMovie Help topic:
    http://help.apple.com/imovie/#mov3a883915
    You can achieve more precision when entering durations by changing a preference in the menu item iMovie Preferences. Check (tick) the preference for Show Time As HH:MM:SS:frames. This will enable you to enter the duration of stills down to the frame level, rather than full seconds (NTSC is 30 frames per second; PAL is 25 fps). When entering times, type a colon between each time segment, such as 2:50:15, which represents 2 minutes 50 seconds and 15 frames. For 5 seconds 20 frames you would enter 5:20 and so forth.
    Note that the music will only run to the length of the video in the timeline (in your case, the still images). So, after increasing the stills duration you will need to drag the end of the music track as far as required. The stills can be dragged inwards to reduce the duration if necessary.
    John
    Message was edited by: John Cogdell - added Note

  • How to extract data from xml file and store that data inti data base table

    Hii All
    I have one table that table contains one column that column contain an XML file
    I want to extract data from that XML file and want to store that extracted data into an other table.
    That xml file has different different values
    I want to store that values into table in diff diff columns

    Hi,
    I am also facing the same problem.I have a .xml file and i need to import the data into the custom table in oracle database.
    Can you please let me know if you know the solution how to do it in oracle apps.
    Thanks,

  • How to make blank copies of a PDF file and put it into the printer tray.

    Dear experts,
    Before you try printing the data from the FM, How tomake several blank copies of the PDF file  and  put it in the printer tray so that you can print just the data from the function module on it??????
    Please reply.

    Hi drredwood,
    When you open your PDF file a yellow bar will appear on the top of the screen.
    Click on 'Enable All Features'.
    Then you will be able to copy the content from your pdf and to paste in any of the file.
    Regards,
    Florence

  • Hi, extract data from xml file and insert into another exiting xml file

    i am searching code to extract data from xml file and insert into another exiting xml file by a java program. I understood it is easy to extract data from a xml file, and how ever without creating another xml file. We want to insert the extracted data into another exiting xml file. Suggestions?
    1st xml file which has two lines(text1.xml)
    <?xml version="1.0" encoding="iso-8859-1"?>
    <xs:PrintDataRequest xmlns:xs="http://com.unisys.com/Anid"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
    <xs:Person>
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
    These two lines has to be inserted in the existing another xml(text 2.xml) file(at line 3 and 4)
    Regards,
    bubbly

    Jadz_Core wrote:
    RandomAccessFile? If you know where you want to insert it.Are you sure about this? If using this, the receiving file would have to have bytes inserted that exactly match the number of bytes replaced. I'm thinking that you'll likely have to stream through the second XML with a SAX parser and copy information (or insert new information) as you stream with an XML writer of some sort.

  • Extract data from xml file and insert into another exiting xml fil

    hello,
    i am searching extract data from xml file and insert into another exiting xml file by a java program. I understood it is easy to extract data from a xml file, and how ever without creating another xml file. We want to insert the extracted data into another exiting xml file. Suggestions?
    Regards,
    Zhuozhi

    If the files are small, you can load the target file in a DOM document, insert the data from the source file and persist the DOM.
    If the files are large, you probably want to use a StAX or SAX.

Maybe you are looking for

  • File to JMS Scenario - Error is Receiver JMS Adapter

    Hi, I am working on File to JMS scenario. I have deployed all required jars for MQ 6.0.2 in SDM. Create all MQ related objects. I am getting following error for Receiver JMS adapter in CC Monitoring. Please let me know if I have missed anything. Is t

  • T-code to pull the year to date balance in SAP

    Hello All, This is Aswin Seshadri. can some one help me in getting a T-code which can pull the YTD balance for a given set of company codes? The reason, I am preparing a macro for the work I do in my company to update the YTD balance. Best Regards As

  • I do have a gray application DVD that came with my MacBook Pro by how to use it

    I do have a gray application DVD that came with my MacBook Pro by how to use it.

  • How to use NI 6040E in DOS ?

    I wish to use assembly language to set timed-interrupt, so I can read a voltage then output a voltage. What should I do ?

  • Aplication Module Connection

    Is it possible to specify the connection that a certain Aplication module/transaction uses? I need to have a connection open for each user, thats's why i need to tell the application module the connection to use... Please this is very important... Da