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
Inline-Support(3)					User Contributed Perl Documentation					 Inline-Support(3)

NAME
Inline-Support - Support Information for Inline.pm and related modules. DESCRIPTION
This document contains all of the latest support information for "Inline.pm" and the recognized Inline Language Support Modules (ILSMs) available on CPAN. SUPPORTED LANGUAGES
The most important language that Inline supports is "C". That is because Perl itself is written in "C". By giving a your Perl scripts access to "C", you in effect give them access to the entire glorious internals of Perl. (Caveat scriptor :-) As of this writing, Inline also supports: - C++ - Java - Python - Tcl - Assembly - CPR - And even Inline::Foo! :) Projects that I would most like to see happen in the year 2001 are: - Fortran - Ruby - Lisp - Guile - Bash - Perl4 SUPPORTED PLATFORMS
"Inline::C" should work anywhere that CPAN extension modules (those that use XS) can be installed, using the typical install format of: perl Makefile.PL make make test make install It has been tested on many Unix and Windows variants. NOTE: "Inline::C" requires Perl 5.005 or higher because "Parse::RecDescent" requires it. (Something to do with the "qr" operator) Inline has been successfully tested at one time or another on the following platforms: Linux Solaris SunOS HPUX AIX FreeBSD OpenBSD BeOS OS X WinNT Win2K WinME Win98 Cygwin The Microsoft tests deserve a little more explanation. I used the following: Windows NT 4.0 (service pack 6) Perl 5.005_03 (ActiveState build 522) MS Visual C++ 6.0 The "nmake" make utility (distributed w/ Visual C++) "Inline::C" pulls all of its base configuration (including which "make" utility to use) from "Config.pm". Since your MSWin32 version of Perl probably came from ActiveState (as a binary distribution) the "Config.pm" will indicate that "nmake" is the system's "make" utility. That is because ActiveState uses Visual C++ to compile Perl. To install "Inline.pm" (or any other CPAN module) on MSWin32 w/ Visual C++, use these: perl Makefile.PL nmake nmake test nmake install Inline has also been made to work with Mingw32/gcc on all Windows platforms. This is a free compiler for Windows. You must also use a perl built with that compiler. The "Cygwin" test was done on a Windows 98 machine using the Cygwin Unix/Win32 porting layer software from Cygnus. The "perl" binary on this machine was also compiled using the Cygwin tool set ("gcc"). This software is freely available from http://sources.redhat.com/cygwin/ If you get Inline to work on a new platform, please send me email email. If it doesn't work, let me know as well and I'll see what can be done. SEE ALSO
For general information about Inline see Inline. For information about using Inline with C see Inline::C. For sample programs using Inline with C see Inline::C-Cookbook. For information on writing your own Inline Language Support Module, see Inline-API. Inline's mailing list is inline@perl.org To subscribe, send email to inline-subscribe@perl.org AUTHOR
Brian Ingerson <INGY@cpan.org> COPYRIGHT
Copyright (c) 2000-2002. Brian Ingerson. Copyright (c) 2008, 2010, 2011. Sisyphus. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html perl v5.18.2 2012-11-19 Inline-Support(3)
All times are GMT -4. The time now is 01:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy