Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
03-30-2006, 01:48 AM
|
#16
|
Senior Member
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191
Rep:
|
I admit saving the index number in a file is not 100% failsafe. It might not be as important to you to have uniquely named files regardless of the directory they are stored in, but I would like my own script to do that. Maybe it's something I will play with separate from this post. If any one has any better ideas on how to store a global indexing number please give me some ideas. As far as the original problem goes, let me see if I can put everything I have learned together:
Code:
#!/bin/sh
# Courtesy of Chocolate for the original script code.
# And to Archtoad for the "picnum" and $FILE loop code.
# Adapted (probably incorectly) by drkstr.
picdir=`date +%m-%d-%y`
usage="Options: [-c camere name] [-d delete source pictures]"
sourcedir=media/usbdisk/DCIM/100_FUJI
filenum=`ls $/"$sourcedir"/* | cut -c 4- |sort -n -r |head -1`
while getopts ":c:d" options; do
case $options in
c ) newcam=$OPTARG;;
d ) delsrc=$OPTIND;;
h ) echo $usage;;
\? ) echo $usage
exit 1;;
* ) echo $usage
exit 1;;
esac
done
if [ $newcam ]; then
camdir=$newcam
else
camdir='fuji-a303'
fi
mkdir -p "$camdir"
mkdir -p ~/"$camdir/$picdir"
filenum= $filenum + 1 # does filnum++ work in bash?
for FILE in `ls $sourcedir`
do
newfilename='DSC$filenum' # is this valid?
cp -r /"$sourcedir/$FILE" ~"/$camdir/$picdir/$newfilename"
filenum=$filenum + 1
done
if [ $delsrc ]; then
rm /"$sourcedir"/*
fi
As I have said before, I am new to all of this (escpecually bash scripting), and would greatly appreciate anyone looking over the code and giving me some pointers. I will still look into storing an indexing number after this is working, and in case anyone else is interested, will post what I find out.
Thanks!
...drkstr
|
|
|
03-31-2006, 04:12 PM
|
#17
|
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
|
Quote:
Originally Posted by chocolatetoothpaste
... This is bad because it will overwrite the picture I took this morning. ...
|
If the objective here is to avoid overwriting pictures as safely & easily as possible, then I still think making the camera keep track of the numbers is the cleanest way to go.
I have repeated my automatic numbering experiment on my cell phone, a Sony Ericsson W600i, with the same result. I now believe that the normal behavior of any digital cameras when saving pictures is to add 1 to the highest serial # in its memory. If memory is empty, that means start (over) at 1. If anyone has a camera or phone, that does not do this, I'd like to hear about it.
I, like drkstr, believe that unique picture names are good for many reasons; not just the avoidance of overwriting when transferring. If that is true for you also, then why not let the camera (or phone) do the work of keeping track of the #'s?
All that is required is to leave one picture on the camera; and that is safe, easy, & scriptable. the algorithm is: - Make all pics on cam r/w.
- (Optional) On cam, delete 1st (old) pic.
- Copy all pics from cam to box.
- On cam, make last pic r/o.
- On cam, delete all pics.
- On cam, make last pic r/w.
- (Optional) On box, find & delete any duplicate pics.
Here is my revised code:
Code:
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# WARNING 1
#
# Mount points are DYNAMIC, this code does NOT take that into account.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# WARNING 2
#
# I believe, from experience, that sorting the 'ls' output is unnecessary
# -- 'ls' lists in directory order, which is both chronlogical & serial.
# At least in this case.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
### Define vars
# CAMERA=<path_to_pics_on_cam>
# DESTDIR=<path_to_pics_on_box>
CAMERA=/mnt/flash/image/camera_semc/100msdcf # on my sys., today -- cell phone
DESTDIR=~/Pictures/SE_W600i-image-camera_semc-100msdcf
PIC-0="$CAMERA/`ls $CAMERA | head -1`"
PIC-n="$CAMERA/`ls $CAMERA | tail -1`"
# Make all pics on cam r/w.
chmod 755 $CAMERA/*
# On cam, delete 1st (old) pic.
rm $PIC-0
# Copy all pics from cam to box.
cp $CAMERA/* $DESTDIR
# On cam, make last pic r/o.
chmod -w $CAMERA/`ls $CAMERA |tail -1`
# On cam, delete all pics.
rm $CAMERA/*
# On cam, make last pic r/w.
chmod u+w $CAMERA/*
# for safety -- this duplicates step 1.
# (Optional) On box, find & delete any duplicate pics.
# Not implemented -- no dupes were copied
Now, just because I think that script controlled renumbering is unnecessary to solve the original problem, doesn't meant that it isn't interesting or useful for something else.
|
|
|
03-31-2006, 09:01 PM
|
#18
|
Senior Member
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191
Rep:
|
Originally, I disagreed with archtoad's method of leaving the last pic behind simply because of annoyance. However I think I am now starting to lean more in that direction. This would eliminate the need to store an indexing counter, and seems easy enough to leave the last pic behind with the script posted by archtoad. All you would have to do is combine that in the "if [ $delsrc ]; then" section of the original script posted by chocolate. This is something I am going to play around with a little bit more.
regards,
...drkstr
|
|
|
04-01-2006, 11:22 PM
|
#19
|
LQ Newbie
Registered: Mar 2006
Posts: 6
Original Poster
Rep:
|
Quote:
Originally Posted by drkstr
Originally, I disagreed with archtoad's method of leaving the last pic behind simply because of annoyance. However I think I am now starting to lean more in that direction. This would eliminate the need to store an indexing counter, and seems easy enough to leave the last pic behind with the script posted by archtoad. All you would have to do is combine that in the "if [ $delsrc ]; then" section of the original script posted by chocolate. This is something I am going to play around with a little bit more.
regards,
...drkstr
|
Here is the pinch, what happens when you put a different memory card in? Then you lose that reference point you had with the picture. Refering back to my original intentions, if you unoad BOTH of those cards in the same day, then they are conveniently put in the same folder. If you only have one card, or only have a phone or whatever, archtoad's method may work for you. Be VERY STRONGLY advised this is POOR programming practice.
|
|
|
04-03-2006, 11:18 AM
|
#20
|
LQ Newbie
Registered: Mar 2006
Posts: 6
Original Poster
Rep:
|
Mission accomplished! The script has reached the point I want it to. It will rename pictures from DSCF0001.x to pic0001.jpg or mov0001.avi, since my camera does movies too. Plus, if there is already a folder with todays date, it will see what pictures are in that folder, and re-increment the picture numbers! With the option of arguments and such, I think this is one fine little script! I hope someone can benefit from this. I know I have. I have become more familiar with shell scripting now. If anyone has some features they have added to this script, please post them so we can all benefit! Thanks to all who have helped!
Code:
#!/bin/bash
#script by ross paskett (aka chocolatetoothpaste) - script to transfer files from my camera, with args!
picdir=`date +%m.%d.%y`
usage="Options: [-c camera name] [-d delete source pictures]"
camsrc=/media/usbdisk/DCIM/100_FUJI
while getopts ":c:d" options; do
case $options in
c ) newcam=$OPTARG;;
d ) delsrc=$OPTIND;;
h ) echo $usage;;
\? ) echo $usage
exit 1;;
* ) echo $usage
exit 1;;
esac
done
if [ $newcam ]; then
camdir=$newcam
else
camdir='fuji-a303'
fi
dst=~/$camdir/$picdir
mkdir -p ~/"$camdir/$picdir"
if [ ! -e "$camsrc" ];then
echo "Camera is not attached or incorrect path:"
echo "$camsrc"
exit 1
fi
for exstnc in $camsrc/*;do
if [ ! -e $exstnc ];then
echo "No pictures on camera!"
exit 1
fi
done
clear
echo "Transfering pictures:"
cd $camsrc
for fl in *;
do
campic=`echo $fl | cut -dF -f2 | cut -d\. -f1`
extn=`echo $fl | cut -d\. -f2 | tr [A-Z] [a-z]`
if [ "X$extn" = "Xjpg" ];then
pref="pic"
else
pref="mov"
fi
firstNum="$pref$campic"."$extn"
cd $dst
if [ -f "$firstNum" ];then
cd $dst
if [ "X$extn" = "Xjpg" ];then
lastNum=`for x in *."$extn"
do
echo $x | cut -dc -f2 | cut -d\. -f1
done | sort | tail -n1`
else
lastNum=`for x in *."$extn"
do
echo $x | cut -dv -f2 | cut -d\. -f1
done | sort | tail -n1`
fi
if [ $lastNum -lt 9 ];then
lastNum="$pref"000`expr $lastNum + 1`."$extn"
elif [ $lastNum -lt 99 ];then
lastNum="$pref"00`expr $lastNum + 1`."$extn"
elif [ $lastNum -lt 999 ];then
lastNum="$pref"0`expr $lastNum + 1`."$extn"
else
lastNum="$pref"`expr $lastNum + 1`."$extn"
fi
echo "$dst/$lastNum"
cp "$camsrc/$fl" "$dst/$lastNum"
else
cd $camsrc
echo "$dst/$firstNum"
cp $fl "$dst/$firstNum"
fi
done
if [ $delsrc ]; then
echo " "
for DEL in $camsrc/*; do
echo "Deleting: $DEL"
rm -f "$DEL"
done
fi
echo "Transfer complete!"
echo " "
Last edited by chocolatetoothpaste; 08-29-2007 at 12:11 PM.
|
|
|
All times are GMT -5. The time now is 05:33 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|