Sponsored Content
Top Forums Shell Programming and Scripting BASH: Script jams Cygwin to 100% CPU - Post 302455045 by SilversleevesX on Monday 20th of September 2010 03:54:16 PM
Old 09-20-2010
BASH: Script jams Cygwin to 100% CPU -

I'd like to streamline the code more than a bit to get it to run faster.

There's a thread about this and related issues of mine on the Cygwin mailing-list, but I want to eliminate any chances it might just be inefficient/inelegant/crappy code. A previous run of the same script on both Cygwin and Ubuntu 9.04's GNOME Terminal, using a source file and a list file of equal length and content, had a significant difference in execution time (2m20s versus just under 3/4 of an hour, GNOME:Cygwin).

The code:
Code:
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

while read 'line';
do
#8-point check:
	cate=$(exiv2 -g Iptc.Application2.Category -Pv $line)
	if [[ "$cate" == "" ]]; then cate2=" Category Tag";fi
	cred=$(exiv2 -g Iptc.Application2.Credit -Pv $line)
	if [[ "$cred" == "" ]]; then cred2=" Credit Tag";fi
	sour=$(exiv2 -g Iptc.Application2.Source -Pv $line)
	if [[ "$sour" == "" ]]; then sour2=" Source Tag";fi
	writ=$(exiv2 -g Iptc.Application2.Writer -Pv $line)
	if [[ "$writ" == "" ]]; then writ2=" Writer Tag";fi
	trans=$(exiv2 -g Iptc.Application2.TransmissionReference -Pv $line)
	if [[ "$trans" == "" ]]; then trans2=" Transmission Reference Tag";fi
	fixid=$(exiv2 -g Iptc.Application2.FixtureId -Pv $line)
	if [[ "$fixid" == "" ]]; then fixid2=" Event/Fixture Identifier Tag";fi
	objnm=$(exiv2 -g Iptc.Application2.ObjectName -Pv $line)
	if [[ "$objnm" == "" ]]; then objnm2=" Object Name Tag";fi
	locn=$(exiv2 -g Iptc.Application2.SubLocation -Pv $line)
	if [[ "$locn" == "" ]]; then locn2=" Location Tag";fi
echo -e "Evaluating File #$x \ $line."
iptc=$(echo $cate2$cred2$sour2$writ2$trans2$fixid2$objnm2$locn2)
case "$iptc" in 
 "" ) ;;
 * ) echo -e "$line:$iptc">>fieldsmissing.txt 
 y=$[y+1]
 ;;
esac
x=$[x+1]
unset cate2
unset cred2
unset sour2
unset writ2
unset trans2
unset fixid2
unset objnm2
unset iptc
done<list.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

I wouldn't pick on this script for any other reason than: since uninstalling one or two binaries from the Cygwin mirrors and from elsewhere, this is the only script (written by YT within the last two months ) that consistently raises CPU usage, as observed in Task Manager by me, to between 94 and 100% usage while it's being executed. Which is Cygwin "biting itself in the a**," to coin a phrase; the longer the cycle time the longer it takes for a script to finish.

Anyone's advice on how to streamline the code would be much appreciated.

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
EXIV2(1)						      General Commands Manual							  EXIV2(1)

NAME
exiv2 - Image metadata manipulation tool SYNOPSIS
exiv2 [options] [action] file ... DESCRIPTION
exiv2 is a program to read and write Exif, IPTC and XMP image metadata and image comments. The following image formats are supported: Type Exif IPTC XMP Image comments ------------------------------------------------------------- JPEG Read/Write Read/Write Read/Write Read/Write EXV Read/Write Read/Write Read/Write Read/Write CR2 Read/Write Read/Write Read/Write - CRW Read/Write - - Read/Write MRW Read Read Read - TIFF Read/Write Read/Write Read/Write - DNG Read/Write Read/Write Read/Write - NEF Read/Write Read/Write Read/Write - PEF Read/Write Read/Write Read/Write - ARW Read Read Read - RW2 Read Read Read - SR2 Read Read Read - SRW Read/Write Read/Write Read/Write - ORF Read/Write Read/Write Read/Write - PNG Read/Write Read/Write Read/Write Read/Write PGF Read/Write Read/Write Read/Write Read/Write RAF Read Read Read - EPS - - Read/Write - XMP - - Read/Write - GIF - - - - PSD Read/Write Read/Write Read/Write - TGA - - - - BMP - - - - JP2 Read/Write Read/Write Read/Write - o Support for GIF, TGA and BMP images is minimal: the image format is recognized, a MIME type assigned to it and the height and width of the image are determined. o Reading other TIFF-like RAW image formats, which are not listed in the table, may also work. ACTIONS
The action argument is only required if it is not clear from the options which action is implied. pr | print Print image metadata. This is the default action, i.e., the command exiv2 image.jpg will print a summary of the image Exif metadata. ex | extract Extract metadata to *.exv, XMP sidecar (*.xmp) and thumbnail image files. Modification commands can be applied on-the-fly. in | insert Insert metadata from corresponding *.exv, XMP sidecar (*.xmp) and thumbnail files. Use option -S .suf to change the suffix of the input files. Since files of any supported format can be used as input files, this command can be used to copy the metadata between files of different formats. Modification commands can be applied on-the-fly. rm | delete Delete image metadata from the files. ad | adjust Adjust Exif timestamps by the given time. Requires at least one of the options -a time, -Y yrs, -O mon or -D day. mo | modify Apply commands to modify (add, set, delete) the Exif, IPTC and XMP metadata of image files. Requires option -c, -m or -M. mv | rename Rename files and/or set file timestamps according to the Exif create timestamp. Uses the value of tag Exif.Photo.DateTimeOriginal or, if not present, Exif.Image.DateTime to determine the timestamp. The filename format can be set with -r fmt, timestamp options are -t and -T. fi | fixiso Copy the ISO setting from one of the proprietary Nikon or Canon makernote ISO tags to the regular Exif ISO tag, Exif.Photo.ISOSpeedRatings. Does not overwrite an existing standard Exif ISO tag. fc | fixcom Fix the character encoding of Exif Unicode user comments. Decodes the comment using the auto-detected or specified character encod- ing and writes it back in UCS-2. Use option -n to specify the current encoding of the comment if necessary. OPTIONS
-h Display help and exit. -V Show the program version and exit. -v Be verbose during the program run. -q Silence warnings and error messages from the Exiv2 library during the program run (quiet). Note that options -v and -q can be used at the same time. -Q lvl Set the log-level to 'd'(ebug), 'i'(nfo), 'w'(arning), 'e'(rror) or 'm'(ute). The default log-level is 'w'. -Qm is equivalent to -q. All log messages are written to standard error. -b Show large binary values (default is to suppress them). -u Show unknown tags (default is to suppress tags which don't have a name). -g key Only output info for this Exiv2 key (grep). Multiple -g options can be used to grep info for several keys. -n enc Charset to use to decode Exif Unicode user comments. enc is a name understood by iconv_open(3), e.g., 'UTF-8'. -k Preserve file timestamps when updating files (keep). Can be used with all options which update files. The flag is ignored by read- only options. -t Set the file timestamp according to the Exif create timestamp in addition to renaming the file (overrides -k). This option is only used with the 'rename' action. -T Only set the file timestamp according to the Exif create timestamp, do not rename the file (overrides -k). This option is only used with the 'rename' action. Note: On Windows you may have to set the TZ environment variable for this option to work correctly. -f Do not prompt before overwriting existing files (force overwrite). -F Do not prompt before renaming files (Force rename). Appends '_1' ('_2', ...) to the name of the new file. -a time Time adjustment in the format [-]HH[:MM[:SS]]. This option is only used with the 'adjust' action. Examples: 1 adds one hour, 1:01 adds one hour and one minute, -0:00:30 subtracts 30 seconds. -Y yrs Time adjustment by a positive or negative number of years, for the 'adjust' action. -O mon Time adjustment by a positive or negative number of months, for the 'adjust' action. -D day Time adjustment by a positive or negative number of days, for the 'adjust' action. -p mode Print mode for the 'print' action. Possible modes are: s : print a summary of the Exif metadata (the default) a : print Exif, IPTC and XMP metadata (shortcut for -Pkyct) t : interpreted (translated) Exif tags (-PEkyct) v : plain Exif tag values (-PExgnycv) h : hexdump of the Exif data (-PExgnycsh) i : IPTC datasets (-PIkyct) x : XMP properties (-PXkyct) c : JPEG comment p : list available image previews, sorted by preview image size in pixels -P flgs Print flags for fine control of the tag list ('print' action). Allows control of the type of metadata as well as data columns included in the print output. Valid flags are: E : include Exif tags in the list I : IPTC datasets X : XMP properties x : print a column with the tag number g : group name k : key l : tag label n : tag name y : type c : number of components (count) s : size in bytes v : plain data value t : interpreted (translated) data h : hexdump of the data -d tgt Delete target(s) for the 'delete' action. Possible targets are: a : all supported metadata (the default) e : Exif section t : Exif thumbnail only i : IPTC data x : XMP packet c : JPEG comment -i tgt Insert target(s) for the 'insert' action. Possible targets are the same as those for the -d option, plus a modifier: X : Insert metadata from an XMP sidecar file <file>.xmp. The remaining insert targets determine what metadata to insert from the sidecar file. Possible are Exif, IPTC and XMP and the default is all of these. Note that the inserted XMP properties include those converted to Exif and IPTC. Only JPEG thumbnails can be inserted (not TIFF thumbnails), they need to be named file-thumb.jpg. -e tgt Extract target(s) for the 'extract' action. Possible targets are the same as those for the -d option, plus a target to extract pre- view images and a modifier to generate an XMP sidecar file: p[<n>[,<m> ...]] : Extract preview images. The optional comma separated list of preview image numbers is used to determine which preview images to extract. The available preview images and their numbers are displayed with the 'print' option -pp. X : Extract metadata to an XMP sidecar file <file>.xmp. The remaining extract targets determine what metadata to extract to the sidecar file. Possible are Exif, IPTC and XMP and the default is all of these. -r fmt Filename format for the 'rename' action. The format string follows strftime(3) and supports the following keywords: :basename: - original filename without extension :dirname: - name of the directory holding the original file :parentname: - name of parent directory Default filename format is %Y%m%d_%H%M%S. -c txt JPEG comment string to set in the image ('modify' action). This option can also be used with the 'extract' and 'insert' actions to modify metadata on-the-fly. -m file Command file for the 'modify' action. This option can also be used with the 'extract' and 'insert' actions to modify metadata on- the-fly. -M cmd Command line for the 'modify' action. This option can also be used with the 'extract' and 'insert' actions to modify metadata on- the-fly. The format for the commands is the same as that of the lines of a command file. -l dir Location (directory) for files to be inserted or extracted. -S .suf Use suffix .suf for source files in 'insert' action. COMMANDS
Commands for the 'modify' action can be read from a command file, e.g., exiv2 -m cmd.txt image.jpg or given on the command line, as in exiv2 -M"add Iptc.Application2.Credit String Mr. Smith" image.jpg Note the quotes. Multiple -m and -M options can be combined. When writing Exif, IPTC and XMP metadata, exiv2 enforces only a correct metadata structure. It is possible to write tags with types and values different from those specified in the standards, duplicate Exif tags, undefined tags, or incomplete metadata. While exiv2 is able to read all metadata that it can write, other programs may have difficulties with images that contain non standard-conforming metadata. Command format The format of a command is set | add | del key [[type] value] set Set the value of an existing tag with a matching key or add the tag. add Add a tag (unless key is a non-repeatable IPTC key; nothing prevents you from adding duplicate Exif tags). del Delete all occurrences of a tag (requires only a key). key Exiv2 Exif, IPTC or XMP key. type Byte | Ascii | Short | Long | Rational | Undefined | SShort | SLong | SRational | Comment for Exif keys, String | Date | Time | Short | Undefined for IPTC keys, and XmpText | XmpAlt | XmpBag | XmpSeq | LangAlt for XMP keys. A default type is used if none is explicitly given. The default is determined based on key. value The remaining text on the line is the value. It can optionally be enclosed in single quotes ('value') or double quotes ("value"). The value is optional. Not providing any value is equivalent to an empty value ("") and is mainly useful to create an XMP array property, e.g., a bag. The format of Exif Comment values includes an optional charset specification at the beginning: [charset=Ascii|Jis|Unicode|Undefined ]comment Undefined is used by default if the value doesn't start with a charset definition. The format for IPTC Date values is YYYY-MM-DD (year, month, day), that for IPTC Time values is HH:MM:SS+|-HH:MM, where HH:MM:SS refers to local hour, minute and seconds and +|-HH:MM refers to hours and minutes ahead or behind Universal Coordinated Time (+|- means either a + or a - sign is required). The format of XMP LangAlt values includes an optional language qualifier: [lang=language-code ]text x-default is used by default if the value doesn't start with a language qualifier. An additional command is available to register XMP namespaces: reg prefix namespace Command file format Empty lines and lines starting with # in a command file are ignored (comments). Remaining lines are commands as described above. EXAMPLES
exiv2 *.jpg Prints a summary of the Exif information for all JPEG files in the directory. exiv2 -pi image.jpg Prints the IPTC metadata of the image. exiv2 rename img_1234.jpg Renames img_1234.jpg (taken on 13-Nov-05 at 22:58:31) to 20051113_225831.jpg exiv2 -r':basename:_%Y%m' rename img_1234.jpg Renames img_1234.jpg to img_1234_200511.jpg exiv2 -et img1.jpg img2.jpg Extracts the Exif thumbnails from the two files into img1-thumb.jpg and img2-thumb.jpg. exiv2 -it img1.jpg img2.jpg Inserts (copies) metadata from img1.exv to img1.jpg and from img2.exv to img2.jpg. exiv2 -ep1,2 image.jpg Extracts previews 1 and 2 from the image to the files image-preview1.jpg and image-preview2.jpg. exiv2 -eiX image.jpg Extracts IPTC datasets into an XMP sidecar file image.xmp and in the process converts them to "IPTC Core" XMP schema. exiv2 -iixX image.jpg Inserts IPTC and XMP metadata from an XMP sidecar file image.xmp into image.jpg. The resulting IPTC datasets are converted from the "IPTC Core" XMP schema properties in the sidecar file to the older IPTC IIM4 format. The inserted XMP properties include those in the "IPTC Core" XMP schema. exiv2 -M"set Exif.Photo.UserComment charset=Ascii New Exif comment" image.jpg Sets the Exif comment to an ASCII string. exiv2 -M"set Exif.GPSInfo.GPSLatitude 4/1 15/1 33/1" -M"set Exif.GPSInfo.GPSLatitudeRef N" image.jpg Sets the latitude to 4 degrees, 15 minutes and 33 seconds north. The Exif standard stipulates that the GPSLatitude tag consists of three Rational numbers for the degrees, minutes and seconds of the latitude and GPSLatitudeRef contains either 'N' or 'S' for north or south latitude respectively. exiv2 insert -l/tmp -S.CRW /data/*.JPG Copy all metadata from CRW files in the /tmp directory to JPG files with corresponding basenames in the /data directory. Note that this copies metadata as is, without any modifications to adapt it to the requirements of the target format. Some tags copied like this may not make sense in the target image. SEE ALSO
http://www.exiv2.org/sample.html#modify Sample command files. http://www.exiv2.org/metadata.html Taglists with key and default type values. AUTHORS
exiv2 was written by Andreas Huggel <ahuggel@gmx.net>. This manual page was originally written by KELEMEN Peter <fuji@debian.org>, for the Debian project. Mar 23, 2012 EXIV2(1)
All times are GMT -4. The time now is 08:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy