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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting crontab; copy most recent *.mpg file from local machine to smb storage device
# 1  
Old 05-24-2009
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
# 2  
Old 05-24-2009
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.

Last edited by methyl; 05-24-2009 at 06:07 PM.. Reason: afterthought
# 3  
Old 05-24-2009
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

Last edited by julezsht; 05-24-2009 at 09:06 PM..
# 4  
Old 05-25-2009
Crontab

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

Last edited by diogooute; 05-25-2009 at 12:16 AM..
# 5  
Old 05-26-2009
Some progress, not a lot but a little...

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.

Code:
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.

Last edited by vbe; 05-27-2009 at 05:07 AM.. Reason: removed URL
# 6  
Old 06-02-2009
The fine tuning of your cron needs someone with Red Hat Linux who can test modifications to your code.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find most recent file and copy to another directory.

Very new to shell scripting. Not sure if my title is correct but I will try and explain. Directory has 100+ files with this format, " ABCD_ABC_Abc_AB0126.abc ". When a new file gets created, the 16-19 characters in the file name gets incremented by 1. Ex...todays most recent file is... (14 Replies)
Discussion started by: askvip
14 Replies

2. Shell Programming and Scripting

Help with fetching the data from remote machine from my jumpbox(local machine)

Team, Presently i am running a script from my local box(i.e jumpbox) to all the remote machines.Basically fetching basic queries like pwd,mkdir,touch etc and i am able to successfully fetch it from my local machine.But when i want to check certain database related queries like the dbstat... (20 Replies)
Discussion started by: whizkidash
20 Replies

3. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to 192.168.1.15 Server from my machine, my ip was 192.168.1.99 Source Destination was UP, with IP 192.168.1.15. This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

4. UNIX for Dummies Questions & Answers

Copy files from Linux server local windows machine using a shell script

Hello, I need to create a shell script which will copy files - which are created on particular date and starting with particular name - to local windows XP machine. Is this possible.? Currently it is being done manually using winscp (1 Reply)
Discussion started by: NarayanaPrakash
1 Replies

5. UNIX for Advanced & Expert Users

FTP While transfering files to local machine to remote machine

Hi Am using unix Ksh Am getting the problem while transferring zero size files through the script . When i transfer zero size files from local machine to remote machine manually i can able to do it . My question its beause of zero size files am not able to transfer through script ? or its... (2 Replies)
Discussion started by: Venkatesh1
2 Replies

6. Shell Programming and Scripting

File representing the hard disk storage device

I want example of a file representing the hard disk storage device In UNIX ? (6 Replies)
Discussion started by: tamer11007
6 Replies

7. Shell Programming and Scripting

How to transfer files from unix machine to local machine using shell script?

Hi All.. Am new to Unix!! Am creating a shell script in which a scenario is like i have transfer the output file from unix machine (Server) to local directory (Windows xp). And also i have to transfer the input file from the local directory to Unix machine (Server) Any help from you... (1 Reply)
Discussion started by: vidhyaS
1 Replies

8. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

9. UNIX for Dummies Questions & Answers

Copy file from local machine to server?

I am logged into a server via SSH. There is a file on my desktop of my Windows PC I would like to put on that server. How do I do it? SCP looks the likely method but how does the server know where the file is on the local machine? Thanks. (2 Replies)
Discussion started by: Sepia
2 Replies

10. UNIX for Dummies Questions & Answers

copy files from local drive to telnet unix machine.

i want to run some solaris executable program (text file). i telnet to solaris machine. the text file is on the net drive h: or my local drive on windows system. how can i copy the text file from local drive in windows to remote machine in solaris system? thanks. (4 Replies)
Discussion started by: gary
4 Replies
Login or Register to Ask a Question