Sponsored Content
Top Forums Shell Programming and Scripting BASH: Script jams Cygwin to 100% CPU - Post 302455396 by SilversleevesX on Tuesday 21st of September 2010 12:37:39 PM
Old 09-21-2010
Be that as it may...

I'm trying to re-create the script using one call to exiv2. "-Pnv"/"-Pkv" and grep are no good, because the output of the former is a block of text when set to a variable. So I have it writing "fullfiledata" to an ASCII file thus:
Code:
fullfiledata=$(exiv2 -Pkv $line>file$x)

Calling any part of that back, I'm reminded of the problems I had when first writing a script to perform this function.
Code:
cate1=$(grep Iptc.Application2.Category file$x)
	if [[ -z "$cate" ]]; then cate2=" Category Tag";fi

On the command line, as two separate lines, these will return cate2 as empty if indeed there is such a line as "Iptc.Application2.Category" in file x. Likewise for every variable set to a tag by grep to the end of the set of conditionals (the other 7 tags Exiv2 grepped in the original script).

Where the problem occurs is in assembling the variable iptc: something wants to ignore any and all empties and stock it with the "if set but empty" value of foo2. Printing iptc to a file, then, means I'm getting a "false report" on all the files from the first one in list.txt to the last, (or until I get so annoyed I terminate the script, which is more likely at this point).

It has so far made no difference to include "else" statements setting the value of a particular second variable to nothing.

Here's the revised code, letting out all possible stops and (I think) allowing for most possible combinations of missing fields.
Code:
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
x=1
while read 'line';
do
#8-point check:
	
	fullfiledata=$(exiv2 -Pkv $line>file$x 2>/dev/null)
	cate1=$(grep -o Iptc.Application2.Category file$x)
	if [[ "$cate1" == * ]]; then cate2=" Category Tag";fi
	if [[ "$cate2" != * ]]; then iptc=$(echo "$cate2" ); fi
	cred1=$(grep -o Iptc.Application2.Credit file$x)
	if [[ "$cred" == * ]]; then cred2=" Credit Tag";fi
	if [[ "$cred2" != * ]]; then iptc=$(echo "$cred2" ); fi
	sour1=$(grep -o Iptc.Application2.Source file$x)
	if [[ "$sour" == * ]]; then sour2=" Source Tag";fi
	if [[ "$sour2" != * ]]; then iptc=$(echo "$sour2" ); fi
	writ1=$(grep -o Iptc.Application2.Writer file$x)
	if [[ "$writ" == * ]]; then writ2=" Writer Tag";fi
	if [[ "$writ2" != * ]]; then iptc=$(echo "$writ2" ); fi
	trans1=$(grep -o Iptc.Application2.TransmissionReference file$x)
	if [[ "$trans" == * ]]; then trans2=" Transmission Reference Tag";fi
	if [[ "$trans2" != * ]]; then iptc=$(echo "$trans2" ); fi
	fixid1=$(grep -o Iptc.Application2.FixtureId file$x)
	if [[ "$fixid" == * ]]; then fixid2=" Event/Fixture Identifier Tag";fi
	if [[ "$fixid2" != * ]]; then iptc=$(echo "$fixid2" ); fi
	objnm1=$(grep -o Iptc.Application2.ObjectName file$x)
	if [[ -z "$objnm1" ]]; then objnm2=" Object Name Tag";fi
	if [[ "$objnm2" != * ]]; then iptc=$(echo "$objnm2" ); fi
	locn1=$(grep -o Iptc.Application2.SubLocation file$x)
	if [[ "$locn" == * ]]; then locn2=" Location Tag";fi
	if [[ "$locn2" != * ]]; then iptc=$(echo "$locn2" ); fi
echo -e "Evaluating File #$x \ $line."
if [[ "$cate2" != * ]] && [[ "$cred2" != * ]]; then iptc=$(echo "$cate2$cred2"); fi
if [[ "$cate2" != * ]] && [[ "$cred2" != * ]] && [[ "$sour2" != * ]]; then iptc=$(echo "$cate2$cred2$sour2"); fi
if [[ "$cate2" != * ]] && [[ "$cred2" != * ]] && [[ "$sour2" != * ]] && [[ "$writ2" != * ]]; then iptc=$(echo "$cate2$cred2$sour2$writ2"); fi
if [[ "$cate2" != * ]] && [[ "$cred2" != * ]] && [[ "$sour2" != * ]] && [[ "$writ2" != * ]] && [[ "$trans2" != * ]]; then iptc=$(echo "$cate2$cred2$sour2$writ2$trans2"); fi
if [[ "$cate2" != * ]] && [[ "$cred2" != * ]] && [[ "$sour2" != * ]] && [[ "$writ2" != * ]] && [[ "$trans2" != * ]] && [[ "$fixid2" != * ]]; then iptc=$(echo "$cate2$cred2$sour2$writ2$trans2$fixid2"); fi
if [[ "$cate2" != * ]] && [[ "$cred2" != * ]] && [[ "$sour2" != * ]] && [[ "$writ2" != * ]] && [[ "$trans2" != * ]] && [[ "$fixid2" != * ]] && [[ "$objnm2" != * ]]; then iptc=$(echo "$cate2$cred2$sour2$writ2$trans2$fixid2$objnm2"); fi
if [[ "$cate2" != * ]] && [[ "$cred2" != * ]] && [[ "$sour2" != * ]] && [[ "$writ2" != * ]] && [[ "$trans2" != * ]] && [[ "$fixid2" != * ]] && [[ "$objnm2" != * ]] && [[ "$locn" != * ]]; then iptc=$(echo "$cate2$cred2$sour2$writ2$trans2$fixid2$objnm2"); fi
case "$iptc" in 
 "" ) ;;
 * ) echo -e "$line:$iptc">>fieldsmissingm.txt 
 y=$[y+1]
 ;;
esac
if [[ "$iptc" -gt "" ]]; then
	echo -e "$line:$iptc">>fieldsmissingm.txt 
	y=$[y+1]
fi
rm file$x
x=$[x+1]
done<msxm-eventmissing.txt
if [ "$y" -gt "0" ]; then
	echo -ne "\n$x JPEG files evaluated,\nwith $y missing some or all of their required IPTC tag data.\nFile-by-file is in fieldsmissing.txt.\n"
else 
	echo -ne "\n$x JPEG files evaluated, none missing any required IPTC tag data.\nNo new information was written to fieldsmissing.txt.\n"
fi
IFS=$SAVEIFS

BZT
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to use cygwin to run bash script

Hi, all, I try to run a quite simple bash script mytest.sh in cygwin, it's content is: #!/bin/bash echo "It is my first bash shell" there are three lines in the script. The second line is blank line. When I run it use command: bash c:/mytest.sh, ... (6 Replies)
Discussion started by: Jenny.palmy
6 Replies

2. Shell Programming and Scripting

Help with bash script - Need to get CPU usage as a percentage

I'm writing a bash script to log some selections from a sensors output (core temp, mb temp, etc.) and I would also like to have the current cpu usage as a percentage. I have no idea how to go about getting it in a form that a bash script can use. For example, I would simply look in the output of... (3 Replies)
Discussion started by: graysky
3 Replies

3. Shell Programming and Scripting

Is there a way to make bash [or another shell] use all CPU cores to execute a single script?

I wrote a very simple script that matches combinations of alphabetic characters (1-5). I want to use it to test CPU speeds of different hardware/platforms. The problem is that on multi-core/processor systems, only one CPU is being utilized to execute the script. Is there a way to change that?... (16 Replies)
Discussion started by: ph0enix
16 Replies

4. UNIX for Dummies Questions & Answers

Cygwin bash script and read command

Hello everyone, I am struggling a bit with a batch script that I need to run in cygwin. I work in winXP and I had to write some awk scripts to do some file manipulation, and now I would like to automate the process by just running a batch file so that my colleagues can use it easily. Now, the... (2 Replies)
Discussion started by: Teroc
2 Replies

5. Shell Programming and Scripting

CPU assignment bash script

Hi guys, I'm basically looking for some help with a bash script I've written. It's purpose is to assign process to individual CPU cores once that process hits 15% CPU usage or more. If it drops below 15%, it's unassigned again (using taskset). My problem is that I can't think of a way to... (2 Replies)
Discussion started by: mcky
2 Replies

6. Windows & DOS: Issues & Discussions

run cygwin bash script from notepad++

I'm using Notepad++ to edit my BASH scripts and using CYGWIN to run them from Windows7. In Notepad++ there is a 'Run' capability. How do I get this to run my scripts directly without having to enter the script name from the Cygwin command line? (3 Replies)
Discussion started by: millsy5
3 Replies

7. Shell Programming and Scripting

Cygwin bash script to unmount and mount an XP partition

As stated, I am looking into keeping my backup drive unmounted in normal windows use. Partly this is to address threats like cryptolocker. Since one of my backup drives is an internal drive, it will not likely afford any protection from such a threat. I am thinking of adding code to my rsync script... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

8. Shell Programming and Scripting

Bash script - cygwin (powershell?) pull from GitHub API Parse JSON

All, Have a weird issue where i need to generate a report from GitHub monthly detailing user accounts and the last time they logged in. I'm using a windows box to do this (work issued) and would like to know if anyone has any experience scripting for GitAPI using windows / cygwin / powershell?... (9 Replies)
Discussion started by: ChocoTaco
9 Replies

9. Shell Programming and Scripting

Bash Script (tar + md) on Cygwin

Hi everybody, First, I'm sorry for my bad english! I have the following situation: I have a Windows 2012 R2 with Cygwin installed. The Windows Server is used as a backup Server with Dell AppAssure installed. At the moment, AppAssure saves Backup Targets to a repository on his D. The... (9 Replies)
Discussion started by: fibra3000
9 Replies

10. UNIX for Beginners Questions & Answers

Using BATCH to call a BASH script on CygWin

I am trying to use a batch file to automatically execute a bash script with no luck this far. The batch script looks like this: C:\Cygwin64\bin\bash test.sh I have also tried this: C:\Cygwin64\bin\bash "C:\Cygwin64\bin\test.sh" Needless to say that the windows box has Cygwin... (7 Replies)
Discussion started by: Xterra
7 Replies
All times are GMT -4. The time now is 04:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy