Simple BASH shell script to rename webcam jpg and copy into a new directory.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple BASH shell script to rename webcam jpg and copy into a new directory.
# 1  
Old 03-22-2009
Simple BASH shell script to rename webcam jpg and copy into a new directory.

System: Ubuntu Intrepid Ibex

I'm running webcamd as a sort of "security" program, but I need a script that will archive my webcam.jpg files.

So, take the following file:
/home/slag/www/webcam.jpg

Rename it--preferably with a time stamp.

Place it in say:
/home/slag/www/history/

Copying the file say ever 60 seconds or so.

And that's it. I wont need to run this as a cronjob as I'll just execute the script from a screen when needed.

Thanks guys!

Rob Findlay
# 2  
Old 03-22-2009

Code:
while :
do
    orig=/home/slag/www/webcam.jpg
    dest=/home/slag/www/history
    destfile=${orig%.jpg}$( date +%Y-%m-%d_%H.%M.%S ).jpg
    mv "$orig" "$dest/$destfile"
    sleep 60
done

# 3  
Old 03-22-2009
Quote:
Originally Posted by cfajohnson

Code:
while :
do
    orig=/home/slag/www/webcam.jpg
    dest=/home/slag/www/history
    destfile=${orig%.jpg}$( date +%Y-%m-%d_%H.%M.%S ).jpg
    mv "$orig" "$dest/$destfile"
    sleep 60
done

Thanks again for the help!

This is what I get when i execute:

mv: cannot move `/home/slag/www/webcam.jpg' to `/home/slag/www/history//home/slag/www/webcam2009-03-21_22.43.57.jpg': No such file or directorhe script:

It's doubling the directory somewhere, though I'm so new to bash i don't see where the error is :-(

-R
# 4  
Old 03-22-2009

My mistake; it should be:

Code:
while :
do
    orig=/home/slag/www/webcam.jpg
    dest=/home/slag/www/history
    origfile=${orig##*/}   ## this step was missing
    destfile=${origfile%.jpg}$( date +%Y-%m-%d_%H.%M.%S ).jpg
    echo mv "$orig" "$dest/$destfile"
    sleep 60
done

# 5  
Old 03-22-2009
Quote:
Originally Posted by cfajohnson

my mistake; it should be:

Code:
while :
Do
    orig=/home/slag/www/webcam.jpg
    dest=/home/slag/www/history
    origfile=${orig##*/}   ## this step was missing
    destfile=${origfile%.jpg}$( date +%y-%m-%d_%h.%m.%s ).jpg
    echo mv "$orig" "$dest/$destfile"
    sleep 60
done



thank you!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change directory within a bash shell script

Hi, I have been trying to execute the below command by changing directory and then copying contents of one directory to another by doing some file name manipulations in between. However this isnt working since as soon as the statement completes it goes back to the original folder. Can someone... (5 Replies)
Discussion started by: HikingLife
5 Replies

2. Shell Programming and Scripting

Simple script for resize, crop and optimize jpg

Hi Friends, I'm trying to create a script that allows me to recursively resize, crop (holding the center of the image) and optimize images jpg, jpeg, png for a specific folder and subfolder with the ability to exclude certain folder and its subdirectory. Again, I should to do with this script:... (3 Replies)
Discussion started by: danjde
3 Replies

3. Shell Programming and Scripting

Oop to copy and rename files through SQL Statement in shell Script

#!/bin/sh sqlplus -s "/ as sysdba" << EOF SET HEADING OFF SET FEEDBACK OFF Select pt.user_concurrent_program_name , OUTFILE_NAME FROm apps.fnd_concurrent_programs_tl pt, apps.fnd_concurrent_requests f where pt.concurrent_program_id = f.concurrent_program_id and pt.application_id =... (1 Reply)
Discussion started by: usman_oracle
1 Replies

4. Shell Programming and Scripting

Bash to rename files repeats previous filename in directory

In the below bash processes substitution, if there are 3 files in a directory /home/cmccabe/medex.logs/analysis.log, the filename variable is set to where these files are located. The code does execute, the problem is that if there is a renamed file in the output directory below, it gets... (0 Replies)
Discussion started by: cmccabe
0 Replies

5. Shell Programming and Scripting

Having trouble with find rename jpg command

Hi, I have a large series of directories and subdirectories with many jpgs in them. I need to do two things: 1. Create a copy of each jpg found within it's own subdirectory 2. Rename this copied jpg such that apple.jpg becomes apple_m.jpg I have tried to run the following commands in... (1 Reply)
Discussion started by: atharvan13
1 Replies

6. Shell Programming and Scripting

Bash script to copy apache log files to client directory

Our Apache log files are written to a location on the server that we as clients have no access. Don't ask. Every month, I have to e-mail the administrator to have him manually copy our Apache log files to a directory in our file space. You can probably guess how efficient it is to do things this... (3 Replies)
Discussion started by: gregraven
3 Replies

7. Shell Programming and Scripting

Need a shell script which takes two inputs and copy the files from one directory to other

Hi, I am using solari 10 OS which is having bash shell. I need a shell script which takes user home directory and name of the file or directory as a input and based on that copy the files accordingly to the other directory. example:I hava a machine1 which is having some files in a... (8 Replies)
Discussion started by: muraliinfy04
8 Replies

8. UNIX for Dummies Questions & Answers

Bash script to rename files in a directory

Dear friends, I have created a script to rename all files in a directory by appending the file name with username (who created the file), the date it was created. For example, "apple.doc" should be renamed to "johnFeb23apple.doc" where "john" is the owner and "Feb23" is file created date. It... (4 Replies)
Discussion started by: djsnifer
4 Replies

9. Shell Programming and Scripting

Rename all ".JPG" files to ".jpg" under all subfolders...

Hi, Dear all: One question ! ^_^ I'm using bash under Ubuntu 9.10. My question is not to rename all ".JPG" files to ".jpg" in a single folder, but to rename all ".JPG" files to ".jpg" in all subfolders. To rename all ".JPG" to ".jpg" in a single folder, for x in *.JPG; do mv "$x"... (7 Replies)
Discussion started by: jiapei100
7 Replies

10. Shell Programming and Scripting

shell script to find and copy the files creted in the year 2006 to another directory

Hi All, I am new to UNIX. I will be thankful if some one helps me. I have to write a shell script for one of the requirement. I have files created from Jan 2006 to March 2008. My requirement is to write a script in such a way that 1) To find and copy(not Moving) the files created in the... (2 Replies)
Discussion started by: manas6
2 Replies
Login or Register to Ask a Question