LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-24-2016, 10:41 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Yep, you guessed it -- another bad script.


And this one checks out on the two shellchecks I gave it to, as well.

Code:
#!/bin/bash
if [ ! -f "commented-files.txt" ]; then
    echo "There is no 'commented-files.txt in this directory."
    echo "Can't continue."
    exit 1
fi

 while read -r file0; do
#	comm1=$(exiftool -fast5 -p "home/steve/bin/iptccomment.fmt" "$line" 2>/dev/null)
# comm1=$(exiv2 -q -pc "$file0")
comm1=$(exiftool -fast5  -Comment "$file0")
	if ! [[ -z "$comm1" ]]; then
	echo -e "$file0 has a Comment."
			if [[  "$comm1" = *"CREATOR:GD-JPEG"* ]] || [[  "$comm1" = *"ACDSystems"* ]] || [[ $comm1 =  *"Created with GIMP"* ]]; then
#			if [[ $comm1 =  *"Created with GIMP" * ]]; then
			echo -e "$file0 has a bad Comment. Writing to file."
			echo -e "$file0">>had-bad-comment.txt
            exiftool -fast5 -overwrite_original_in_place -q -Comment= "$file0"
#			jhead -dc "$file0"
			echo -e "Comment data removed from $file0."
			echo -e "$file0">>comment-cleared.txt
		fi
	fi
	
done<commented-files.txt
On one run it wrote the names of the files with "bad" comments to "had-bad-comment.txt," on a subsequent run it didn't. And checking the files afterwards with Gwenview (I don't trust gThumb to update anything), I noticed none of the comments were removed.

Now the 2 scripts this was built from work. Seems to be the way with my scripts: when I try to make things more efficient by combining elements of two shorter scripts (note the long-ish if conditional above), the combination fails to work.

Any ideas?

Carver

Last edited by L_Carver; 12-24-2016 at 10:48 AM. Reason: More detail was needed.
 
Old 12-24-2016, 12:41 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,669

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
So no real obvious syntax errors but the script isn't working as expected. Try adding set -xv after your shebang to enable debugging. You will then be able to see where it goes astray.
 
Old 12-24-2016, 12:46 PM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
so the first time you ran it on the (test?) files, it worked,
the second time you ran it on the (same?) test files it did not work?

could it be that after you ran it the first time (if you are doing this with the same files each time) that the first run changed the (test?) files in a way that would make it so a second run and the (same?) files would not give the desired results due to them being altered by the first run?
 
Old 12-24-2016, 07:00 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would be curious to know what you expect from all the globbing used in your test, ie. all the asterisks you have used will be expanded prior to the test but as
I would think there are no files on your system with those names, I am not sure I understand the need??
 
Old 02-06-2017, 06:08 AM   #5
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Not quite there, but closer

Quote:
Originally Posted by grail View Post
I would think there are no files on your system with those names, I am not sure I understand the need??
The asterisks were intended to have the script (shell?) look for any possible variation on the comment strings returned by
Code:
comm1=$(exiftool -fast5  -s -S -Comment "$file0")
that contain the GD-JPEG substring. There are a few variations on the "GD-JPEG" comment; the one I've seen most often is on the order of
Code:
GD-JPEG v1.0 (using IJG JPEG v62), quality = 90
I think it would limit the scope of the script to have it look for the one I just bold-ed and ignore the other possibilities.

I just tried the if/then test in Konsole and noticed the conditional did not perk up with
Code:
"$file0 has a \"libgd\" Comment.
The longer part of the substring (a Comment from a recently-downloaded JPEG) my script tested for was in lowercase, while the script looks for all caps instead of both. Testing for each one looks like a way forward, unless there's a better way about it.

Thanks for your advice. I hope you'll help me further with this one.

Carver

Last edited by L_Carver; 02-06-2017 at 06:13 AM.
 
Old 02-06-2017, 09:24 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Personally I would force the 'comm' variable to all upper / lower case and then use a simple regex on the resulting string.
 
  


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
Alert when root pw is being guessed at mattp Slackware 6 10-05-2005 01:24 AM
Hi. I'm new! (wow... who would have guessed) everbloom LinuxQuestions.org Member Intro 1 03-24-2004 03:43 PM
sound on rh8 (you've guessed it ac'97!) Ian_Hawdon Red Hat 4 09-06-2003 09:24 AM
yep... Poet LinuxQuestions.org Member Intro 0 07-24-2003 08:47 AM
sound on slackware (you've guessed it ac'97!) Ian_Hawdon Linux - Hardware 5 05-08-2003 01:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 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
Open Source Consulting | Domain Registration