Linux - NewbieThis 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
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.
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.
I call it "badcommentcheck." It uses Exiftool to find and remove what I consider unnecessary strings in the JPEG comment header of files of that type. As it is now, it neither alerts the user when it finds them nor removes them with Exiftool silently when it does.
The code looks like this. (BTW, shellcheck missed the mistakes --if there are any -- with the 'alerts' altogether)
Code:
#!/bin/bash
SAVEIFS=$IFS
IFS=$( echo -e "\n\b")
while read -r line; do
comm1=$(exiftool -fast5 -s -S-Comment "$line")
echo "Checking $file0."
if [ ! -z "$comm1" ];then
echo "$file0 has no comment data. Moving on"
echo "$file0">>nocomment.txt
fi
if [ -n "$comm1" ]; then
echo "$file0 has Comment data."
echo -e "$file0^$comm1" >>hascomment.txt
fi
if [[ "$comm1" = "Created with GIMP" ]]; then
echo -e "$file0 has an unwanted comment. Writing to file."
echo -e "$file0">>has-bad-comment.txt
exiftool -fast5 -overwrite_original_in_place -q -P -Comment="$file0"
echo -e "Comment data removed from $file0."
echo -e "$file0">>comment-cleared.txt
fi
if [[ "$comm1" = "CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality =100." ]];then
echo -e "$file0 has an unwanted comment. Writing to file."
echo -e "$file0">>has-bad-comment.txt
exiftool -fast5 -overwrite_original_in_place -q -P -Comment="$file0"
echo -e "Comment data removed from $file0."
echo -e "$file0">>comment-cleared.txt
fi
done<commented-files.txt
IFS=$SAVEIFS
I've run it on batches of files where either or both of those strings were in more than one JPEG comment. I've even put them in some JPEGs myself with Exiftool to make them more 'conspicuous.'
The questions are:
Where am I making it skip returning the tip-offs to stdout? Or the 'remove' command from Exiftool ('-Comment=' with a null value is equivalent to a 'delete' or -M"del {exiv2} command.)
Carver
Last edited by L_Carver; 11-19-2016 at 08:14 AM.
Reason: Command syntax (Exiftool)
I call it "badcommentcheck." It uses Exiftool to find and remove what I consider unnecessary strings in the JPEG comment header of files of that type. As it is now, it neither alerts the user when it finds them nor removes them with Exiftool silently when it does.
The code looks like this. (BTW, shellcheck missed the mistakes --if there are any -- with the 'alerts' altogether)
I've run it on batches of files where either or both of those strings were in more than one JPEG comment. I've even put them in some JPEGs myself with Exiftool to make them more 'conspicuous.'
The questions are:
Where am I making it skip returning the tip-offs to stdout? Or the 'remove' command from Exiftool ('-Comment=' with a null value is equivalent to a 'delete' or -M"del {exiv2} command.)
Carver
Without your data files, I can't run this myself and get the same results, but I can provide tip: have you tried running the script with tracing? Add -xv after the bash in your first line, or invoke it
Looks to me like the big problem is the lack of a space between "-S" and "-Comment"
Code:
comm1=$(exiftool -fast5 -s -S-Comment "$line")
# should be
comm1=$(exiftool -fast5 -s -S -Comment "$line")
Without that space, nothing is returned, making it appear that no files have any comment (probably why the test got reversed to stop that darn "no comment data" message for every file).
#!/bin/bash
SAVEIFS=$IFS
IFS=$( echo -e "\n\b")
#Changing your first set of if statements to this.
while read -r line; do
comm1=$(exiftool -fast5 -s -S -Comment "$line")
echo "Checking $file0."
if [ ! -z "$comm1" ];then
echo "$file0 has no comment data. Moving on"
echo "$file0">>nocomment.txt
else
echo "$file0 has Comment data."
echo -e "$file0^$comm1" >>hascomment.txt
fi
# the logic behind that was if it is not empty
then it has to have something in it, so we
use the else instead of another test. Cutting
down on time needed to check everything. Causing
a faster run.
#changing your second if statements to this.
if [[ "$comm1" = "Created with GIMP" ]]; then
echo -e "$file0 has an unwanted comment. Writing to file."
echo -e "$file0">>has-bad-comment.txt
exiftool -fast5 -overwrite_original_in_place -q -P -Comment="$file0"
echo -e "Comment data removed from $file0."
echo -e "$file0">>comment-cleared.txt
else
if [[ "$comm1" = "CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality =100." ]];then
echo -e "$file0 has an unwanted comment. Writing to file."
echo -e "$file0">>has-bad-comment.txt
exiftool -fast5 -overwrite_original_in_place -q -P -Comment="$file0"
echo -e "Comment data removed from $file0."
echo -e "$file0">>comment-cleared.txt
fi
fi
done<commented-files.txt
IFS=$SAVEIFS
only the if statements were changed in this example.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.