#1
  1. Me likey breadsticks...
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2003
    Location
    Los Angeles
    Posts
    1,189
    Rep Power
    18

    Seeking a linux shell script for to compare last modified file time.


    Not sure if I should've posted this in Linux or scripts, but I'm basically looking for a bash shell script that will be able to check for a files properties to see if it has been modified within a set amount of time. This is because where I'm hosting my site doesn't allow FTP so my webcam updates to my own linux server, and then I'm going to run a cron script that checks the files properties and if it's been updated in the last 5 minutes SCP to my website.

    I've been trying to do this as a bash shell script however I'm having trouble finding either the right function to get the date properties or parsing text.

    Right now I was approaching it by trying to do a stat -t on the file, however I have to either parse the output of stat or try and read it into an array variable.

    I could get this done a whole lot easier, by just using PHP with wget in my cron, but I figure a bash script would be cleaner (less files) and would also be pretty simple if I just could find out the proper function/syntax.

    -b
    PostgreSQL, it's what's for dinner...
  2. #2
  3. Me likey breadsticks...
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2003
    Location
    Los Angeles
    Posts
    1,189
    Rep Power
    18
    I figured it out, if anyone ever needs something like this here it is for posterity's sake (I'm a newb in linux shell scripting so feel free to point and laugh:
    PHP Code:
    #
    #Ghetto auto SCP script Bryan Encina 10-16-2003 
    #
    #Assumptions:    passwordless SCP has been setup via generation of private/public
    #        keypair and insertion of pub key to webhost user's 
    #        .ssh/authorized_keys file
    #Intended Use:  uploading webcam image from linux server to another webhost
    #        that does not support FTP (only SCP), probably of no use to anyone else
    #Usage:        make an entry in your crontab to run as the user who's setup for passwordless scp
    #        to run this script with the path to your webcam img as a 
    #        command line arg        

    #user settings edit the vars below
    checkduration=300          #if current - timestamp is less than this we have a new file default to 5 minutes
    remoteuser=myremoteuser    #user at remote host
    mydomain=mydomain.com    #the domain/ip of your remote host
    destpath=yourfile        #the path to your remote file

    #do not edit below unless you know what you're doing, but if you did you 
    #wouldn't be using this and you'd be writing your own wouldn't you?
    localfile=$1

    cur_timestamp
    =`date +%s`
    my_stat=`stat -t $localfile 2>/dev/nullread name size blocks unk uid gid dev inode links unk2 unk3 last_access last_mod last_change ioblock << ENDHERE
        
    $(echo $my_stat)
    ENDHERE

    if [ $last_mod ]
    then
        time_diff
    =`expr $cur_timestamp - $last_mod`
        if [ 
    $time_diff -lt $checkduration ]
        
    then    
            
    #echo This is a recent file
            
    scp $localfile $remoteuser@$mydomain:$destpath
        fi
    fi 
    PostgreSQL, it's what's for dinner...
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    1
    Rep Power
    0
    HI,

    is there any ohter possibility to to see if a file has been modified within x minutes.

    On Linux I use find -cmin but under HP-UX -cmin is not available.
    Also stat -t is a good solution on Linux but again the comand is not available on HP-UX.

    Is there anybody that kwows a solution under HP-UX to find out if a file has been changed in the last x minutes.

    Thanks a lot
    ad

IMN logo majestic logo threadwatch logo seochat tools logo