LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-09-2010, 06:56 AM   #1
skifun
LQ Newbie
 
Registered: Jan 2010
Distribution: ubuntu 9.04
Posts: 3

Rep: Reputation: 0
Help for automate script for a webcam


Hello there,

recently I bought a Dlink DCS-2121 web camera in order to upload a snapshot at web server. This damned cam has not an option (I changed lot of firmwares) to create an single only file and overwriting this one, but continuously uploading in directories with random (can not understand where they comes) names, snapshots with filenane based on time, date.

So I am trying to create a cron job in my cpanel menu to find the newest file from those directories , every 2 minutes let's say, and copy this file to a new location. Have searched the forum and found some solutions but I am an experienced user to combine them.

This command
Code:
ls -lrt|grep test|tail -1|awk '{print ""$8}'
seems to find the newest file "test" for example, but I can not modify it to search in all subdirectories and input probably an -exec (or cp) command to copy this file to a new destination and all these in one command.

Thanks for your patience, any help could highly appreciate.
 
Old 01-09-2010, 07:28 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
http://www.itreviews.co.uk/hardware/h1900.htm
Nice!

Your problem is that ls won't list recursively down the directory tree.
You need to use a search function instead, like find, to generate your list of files.
Alternatively, use grep directly.

How are you capturing the photos?

Can you provide an example of the filenames (just ls and copy them over) - one of us may see the pattern and that will simplify your search routine considerably.

I have a feeling you are doing this by a more convoluted method than is needed.
 
Old 01-09-2010, 12:11 PM   #3
skifun
LQ Newbie
 
Registered: Jan 2010
Distribution: ubuntu 9.04
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for reply

I already have read the article you propose and even lot's more. I said I am not experienced in Linux not in computers (although it could be a long conversation for this statement...) I have tried also with firmware upgrade or even downgrade but simply there is not anywhere the option writing on a single file.
Here it is the options it provides.
http://i45.photobucket.com/albums/f7...s/snapshot.jpg


Yes I know that ls is only for current directory but as I said I am not a experienced user. I will try nevertheless to find some solution, and that's why I am asking some help.

There is also another way, with direct url with the help of dlinkddns (http://cam:cam@name.dlinkddns.com/image/jpeg.cgi) but it's a bad idea exposing your password over the net.

The filename could be for today _20100109_185516.jpg or If I used a prefix test for example should be test_20100109_185516.jpg. I tried just a few minutes ago and wrote on web server this folder
/20100109/19/
with images _20100109_190452.jpg and _20100109_190752.jpg (180 sec is the Interval)

What else should I try instead of searching complicated commands ?
 
Old 01-09-2010, 12:37 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Code:
shell# cp -f -T $(find /<searchpath> -name "*" | sort | tail -n1) /<destination-file>
The above is an idea, but not sure if is exactly what you want-- I'm having a slight bit of trouble understanding the situation.

This code finds the latest file (based on numerical sort) in the <searchpath> recursively, and copies it to <destination>

Note that there's not really any sanity checking or error checking, but maybe it's a start.

Sasha
 
Old 01-10-2010, 04:40 PM   #5
skifun
LQ Newbie
 
Registered: Jan 2010
Distribution: ubuntu 9.04
Posts: 3

Original Poster
Rep: Reputation: 0
Yes !

that's what I was looking for, and it plays well.
Added the following line in my cpanel cron job and everything is absolutely ok, bypassing firmware's stupidity.

Code:
cp -f -T $(find /home/username/public_html/directory -name filename* | sort | tail -n1) /home/username/public_html/filename
Thank you very much GrapefruiTgirl
 
Old 01-10-2010, 04:43 PM   #6
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Great! Glad it helped.

As noted though, you may want to throw in some error checking to use it reliably on a production environment.

Cheers!
Sasha
 
  


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
How to automate minicom using script ? kashyap88anirudh Linux - Newbie 1 03-04-2008 02:39 PM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 10:54 AM
Script to automate tasks immortaltechnique Red Hat 2 10-08-2006 11:46 PM
Automate SSH Script Gentoo20 Linux - General 11 03-22-2006 07:21 PM
automate script w/ cron viniosity Linux - Newbie 5 02-02-2005 04:13 PM


All times are GMT -5. The time now is 05:15 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration