crontab; copy most recent *.mpg file from local machine to smb storage device

Hello,

I've been searching your forum for an answer to the following question and whilst I've seen several which may help I'm afraid my inexperience with UNIX systems has got the better of me and I'm incapable of piecing your considerable expertise together.

Problem:
I have a linux box which creates video files hourly, I need to backup these files once they are created to a network share accesible via smb - the files are date stamped; YYYYMMDDHH.mpg

Limitations:
I cannot amend or interface with the encoding process. I cannot seem to write a script which moves the local file/s/folder to the remote share.

Could I write a script which CRONTAB could run each hour that copied the entire folder to the destination directory? Is there any way in which I can chose to not backup the entire folder but instead, only the latest addition/s to the local folder?

Many thanks for taking the time to read my post,

julian

Please state what Operating System you have and which is your preferred shell.
Are the files created in a predicatable manner such that the required cron can run on files which are definitely complete?
It is quite easy if there is a quiet slot when no files can be created.

My first thought is to create a script which copies the files during a quiet time slot, then immediately create a reference file with "touch". After the first instance, use "find -newer" relative to the reference file and re-touch the reference file after the copy. This technique will not work unless there is a regular quiet time slot.

Hi methyl,

Thanks for the reply.

I'm using Red Hat 5, as for my preferred shell; I have none, I'm afraid I'm ignorant and this is my first venture into shell scripting - bash if at all possible. Running this series of commands using CRON?

The video encoding process runs from 00-58minutes passed each hour. There is therefore a two minute window each hour where all the system is doing is writing the file it's just created.

Thanks for your continued patience with my lack of knowledge,

julian

I am new in shell script, but i made atm a script to add in crontab my script to run..
u can do this too...

i made this...

crontab -l > $TEMPFILE
#MODIFY u temp file...
#
# ( check if already exist u script in crontab
# if dont exists
# insert it
# fi
# ) PSEUDOCODE

crontab $TEMPFILE
rm $TEMPFILE

crontab in a terminal:
crontab -l : see u list of registers
crontab -e: edit u register
crontab -r: remove u register

format of crontab

MINUTS HOUR DAYSOFMONTH MONTH DAYOFWEEK COMMAND
0-57 * * * * FOLDER/script.sh

i got some trouble trying to put the "*" on file using bash and nobody aswer the other thread... so i used the begin-end like that...

MINUTS HOUR DAYSOFMONTH MONTH DAYOFWEEK COMMAND
0-57 0-23 1-31 1-12 0-7 FOLDER/script.sh

DAY OF WEEK: 0 and 7 is the same day...

this crontab is just to run for u user... to use for all user is another file...(i think is in /etc/crontab)...

PS: if need i can send my code to u or i can explain again

i hope this ll help u ,
Diogo

Thanks for all your help methyl, diogooute

I've made a little progress, I'm comfortable with calling scripts I create using CRONTAB. I haven't used your touch method, I've been slightly free-wheeling... Whilst the below method isn't the most inspired, it will also mean that I won't backup any sections of video that failed to encode for the full 58minutes. This is a bonus if I specify that CRONTAB run an amended flavour of this script in the 2minute downtime - this is actually beneficial as clips <58minutes would be of little use.

I've gone for using the -mmin command within find which should allow me to find files modofied with X minutes of the current time. Whilst this is not bomb-proof, I know that the other contents of the source folder won't be amended...

I'm finding that the results of my find query return the folder location ./ and therefore experimented with removing this using the sed command and failed, despite trawling through forum after forum which detail that escaping the / should be easy, I can't seem to do this.

find -name \*.mpg -mmin -3 > newest_mpg.tmp
    #sed 's ..$  ' newest_mpg.tmp > newest_mpg.tmp
    newestmpg=$(cat newest_mpg.tmp)
    echo $newestmpg
    smbclient \\\\10.10.10.3\\public -u smb_user -p smb_pass -c "; prompt; put $newestmpg; exit"

Criticism welcome, I'd appreciate any pointers -

Thanks again.

The fine tuning of your cron needs someone with Red Hat Linux who can test modifications to your code.