Need help optimizing my script i´ve found somewhere

Started by Maximus1, April 06, 2022, 04:00:50 AM

Previous topic - Next topic

Maximus1

Hi,
i own round about 120 GB pictures (Picdumps etc.) and photos.
Actually, i try to organize them as follows.

sh photo-cleanup.sh /var/www/html/data/Christina/files/Photos/

#!/bin/sh

albumdir=$1

# use below variables if running on the server
nextclouddir="/var/www/html"
# user who owns the photos
nextclouduser="admin"

echo "Setting Filename date from DateTimeOriginal..."
exiftool "-Filename<$EXIF:DateTimeOriginal" -r -F -d "%Y%m%d_%H%M%S.jpg" -overwrite_original -ext jpg -makernotes:all= "$albumdir"

echo "Setting DateTimeOriginal from filename date..."
exiftool "-DateTimeOriginal<Filename" -r -F -overwrite_original -ext jpg "$albumdir"

echo "Setting modified date from DateTimeOriginal..."
exiftool "-filemodifydate<datetimeoriginal" -r -F -overwrite_original "$albumdir"

echo "deleting trailer if exist"
exiftool -trailer:all= "$albumdir"

# uncomment the below command if running on the server
echo "Re-scanning your Nextcloud data directory..."
sudo -u www-data php occ files:scan "$nextclouduser"


exit 0


I want to compact it and touch every file only once and not 4 times like now. So i wrote the following which is not working.

#!/bin/sh

albumdir=$1

# use below variables if running on the server
nextclouddir="/var/www/html"
# user who owns the photos
nextclouduser="XxX"

echo "Setting Filename date from DateTimeOriginal..."
exiftool -v "-Filename<DateTimeOriginal" -r -F -d "%Y%m%d_%H%M%S.jpg" -if '(not $DateTimeOriginal eq $Filename)' "-DateTimeOriginal<Filename" -if '(not $DateTimeOriginal)' -overwrite_original -ext jpg -trailer:all= -makernotes:all= *.jpg "$albumdir"

# uncomment the below command if running on the server
echo "Re-scanning your Nextcloud data directory..."
sudo -u www-data php occ files:scan "$nextclouduser"


exit 0


As result i get
root@1872c29089bf:/123#  sh photo-cleanup.sh /var/www/html/data/Christina/files/Photos/
Setting Filename date from DateTimeOriginal...
-------- 20161008_173504.jpg (failed condition)
-------- 20201202_000000.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20200614_190942.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20151121_120103.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/IMG-20200312-WA0032.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20190317_002300.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20181130_134409.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20190114_202323.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20160927_160455.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20190204_191749.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20181212_101253.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20211008_151050.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20200517_131134.jpg (failed condition)
-------- /var/www/html/data/Christina/files/Photos/20161010_133050.jpg (failed condition)


Can you tell me what i´m doing wrong?

StarGeek

The -if option is not an "if ... then" statement.  When you have multiple -if options, they all must be true for the command to work.  Two of the operations in your command are conflicting
"-Filename<$EXIF:DateTimeOriginal"
and
"-DateTimeOriginal<Filename"
will need to be in separate commands.  So the most you can trim it down to is two commands.  You can add the -trailer:all= -makernotes:all= to both commands so you don't need to run it separately.

Also, very minor but the first one is Common Mistake #5b.  You don't need the dollar sign there.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).