Sponsored Content
Top Forums Shell Programming and Scripting Need help optimizing this piece of code (Shell script Busybox) Post 302561184 by snappy46 on Monday 3rd of October 2011 11:56:29 AM
Old 10-03-2011
Need help optimizing this piece of code (Shell script Busybox)

I am looking for suggestions on how I could possibly optimized that piece of code where most of the time is spend on this script. In a nutshell this is a script that creates an xml file(s) based on certain criteria that will be used by a movie jukebox.

Example of data:

$SORTEDTMP= it is a file created using find that contain all the movies (200+) on my drive. ex:
/USB/movies/science-fiction/alien/alien.avi
/USB/movies/comedy/funnymovie/funnymovie.avi
....etc

$MOVIESPATH= string = "/USB/movies/science-fiction/"

Movieinfo = Just an xml file containing data about the movie; I only care about extracting the movie title if the file exist vs using the filename as the movie title which may or may not be accurate.

All the other jpg, bmp may or may not exist and appropriate action are taken based on their existence.

Currently the created xml file is being appended for every movies that match the grep MOVIESPATH which could include all the movies. This part of the code is called up many times to create an xml files for all the different movie category including "All movies". I am not sure if I can store all the data in a temporary place in memory and before I leave this loop write the file would be faster ????? I don't know and do not have much experience.

So I'll ask again does anyone sees anything there that could be optimized that would significantly increase the running speed of this piece of code.

Code:
 
grep "$MOVIESPATH" $SORTEDTMP | while read plik
do
  MovieName=`basename "$plik" | sed 's/\(.*\)\..*/\1/'`
  DirectoryPath=`dirname "$plik"`
  if [ -e "$DirectoryPath/MovieInfo.nfo" ];
  then
     MOVIEINFO="$DirectoryPath/MovieInfo.nfo"
     MOVIETITLE=`grep "<title>.*<.title>" "$MOVIEINFO" | sed -e "s/^.*<title/<title/" | cut -f2 -d">"| cut -f1 -d"<"`
  else
     MOVIETITLE=$MovieName
  fi
  if [ -e "$DirectoryPath/folder.jpg" ];
  then
     MOVIEPOSTER=$DirectoryPath/folder.jpg
  elif [ -e "$DirectoryPath/${MovieName}.jpg" ];
  then
     MOVIEPOSTER=$DirectoryPath/${MovieName}.jpg
  else  
     MOVIEPOSTER=/usr/local/etc/srjg/nofolder.bmp
  fi
 
  if [ -e "$DirectoryPath/about.jpg" ];
  then
     MOVIESHEET=$DirectoryPath/about.jpg
  elif [ -e "$DirectoryPath/0001.jpg" ];
  then
     MOVIESHEET=$DirectoryPath/0001.jpg
  elif [ -e "$DirectoryPath/${MovieName}_sheet.jpg" ];
  then
     MOVIESHEET=$DirectoryPath/${MovieName}_sheet.jpg
  else  
     MOVIESHEET=/usr/local/etc/srjg/NoMovieinfo.bmp
  fi
  echo -e '<Movie>
  <title>'$MOVIETITLE'</title>
  <poster>'$MOVIEPOSTER'</poster>
  <info>'$MOVIESHEET'</info>
  <file>'$plik'</file>
  </Movie>' >> $RSS 
done

Any help appreciated. Thank you.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

a piece of code, plz help to review

use "getopts" to get params from command. Need replace black with a specified string like "%20 DEFAULT_DELIM=%20 ... while getopts dek:f:t:vh OPTION do case $OPTION in t) DELIM=`tvar=/'"$OPTARG"'/ svar="$DEFAULT_DELIM" awk 'BEGIN{T=ENVIRON;S=ENVIRON; while(index(T,S)!=0){S=S"0"};print... (0 Replies)
Discussion started by: anypager
0 Replies

2. Shell Programming and Scripting

what does this piece of code do?

Hi All, I am trying to understand and change some code written by some programmer a while ago. There are following three lines of code that I am unable to grasp. Could anybody please help me understand it? 1) cd - > /dev/null 2) fname=`basename "$1"` where $1 = /dirA/dirB/a.txt ... (3 Replies)
Discussion started by: Vikas Sood
3 Replies

3. Shell Programming and Scripting

script or piece of code where the data returned by a stored procedure you are writing

hi fndz. Can you please help me with the code if I call a stored procedure from my shell script and stored procedure returns a cursor, cursor output should be saved to a file (3 Replies)
Discussion started by: enigma_83
3 Replies

4. Shell Programming and Scripting

Enabling sh shell in BusyBox

Hi, Does anybody know how to enable the shell sh while creating Ramdisk fs using BusyBox? while creating a configuration using the GUI, I see options only for the ash shell. Is there some option in the config file that gets created with which I can enable the sh shell also apart from the ash... (0 Replies)
Discussion started by: jake24
0 Replies

5. Shell Programming and Scripting

Looking for guidance (comments) on a piece of code

Hello -- I am trying to learn to do a little sed and awk scripting to search for text and numbers in text files (text processing/manipulation). My professor gave me a piece of uncommented code and I am very unfamiliar w/ the language. Can someone help me with comments so I can understand what is... (2 Replies)
Discussion started by: smithan05
2 Replies

6. Programming

what is the name of this piece of code

while ((numRead = read(inputFd, buf, BUF_SIZE)) > 0) if (write(outputFd, buf, numRead) != numRead) fatal("couldn't write whole buffer"); if (numRead == -1) errExit("read"); if (close(inputFd) == -1) errExit("close input"); if (close(outputFd) == -1) errExit("close output"); ... (1 Reply)
Discussion started by: fwrlfo
1 Replies

7. Shell Programming and Scripting

Optimizing the code

Hi, I have two files in the format listed below. I need to find out all values from field 12 to field 20 present in file 2 and list them in file3(format as file2) File1 : FEIN,CHRISTA... (2 Replies)
Discussion started by: nua7
2 Replies

8. Shell Programming and Scripting

Bash Script to Ash (busybox) - Beginner

Hi All, I have a script that I wrote on a bash shell, I use it to sort files from a directory into various other directories. I have an variable set, which is an array of strings, I then check each file against the array and if it is in there the script sorts it into the correct folder. But... (5 Replies)
Discussion started by: sgtbobie
5 Replies

9. Shell Programming and Scripting

Need a piece of shell scripting to remove column from a csv file

Hi, I need to remove first column from a csv file and i can do this by using below command. cut -f1 -d, --complement Mytest.csv I need to implement this in shell scripting, Whenever i am using the above command alone in command line it is working fine. I have 5 files in my directory and... (3 Replies)
Discussion started by: Samah
3 Replies

10. Shell Programming and Scripting

Optimizing the Shell Script [Expert Advise Needed]

I have prepared a shell script to find the duplicates based on the part of filename and retain latest. #!/bin/bash if ; then mkdir -p dup fi NOW=$(date +"%F-%H:%M:%S") LOGFILE="purge_duplicate_log-$NOW.log" LOGTIME=`date "+%Y-%m-%d %H:%M:%S"` echo... (6 Replies)
Discussion started by: gold2k8
6 Replies
Class::DBI::Pager(3pm)					User Contributed Perl Documentation				    Class::DBI::Pager(3pm)

NAME
Class::DBI::Pager - Pager utility for Class::DBI SYNOPSIS
package CD; use base qw(Class::DBI); __PACKAGE__->set_db(...); use Class::DBI::Pager; # just use it # then, in client code! package main; use CD; my $pager = CD->pager(20, 1); # ($items_per_page, $current_page) my @disks = $pager->retrieve_all; DESCRIPTION
Class::DBI::Pager is a plugin for Class::DBI, which glues Data::Page with Class::DBI. This module reduces your work a lot, for example when you have to do something like: * retrieve objects from a database * display objects with 20 items per page In addition, your work will be reduced more, when you use Template-Toolkit as your templating engine. See "EXAMPLE" for details. EXAMPLE
# Controller: (MVC's C) my $query = CGI->new; my $template = Template->new; my $pager = Film->pager(20, $query->param('page') || 1); my $movies = $pager->retrieve_all; $template->process($input, { movies => $movies, pager => $pager, }); # View: (MVC's V) Matched [% pager.total_entries %] items. [% WHILE (movie = movies.next) %] Title: [% movie.title | html %] [% END %] ### navigation like: [1] [2] [3] [% FOREACH num = [pager.first_page .. pager.last_page] %] [% IF num == pager.current_page %][[% num %]] [% ELSE %]<a href="display?page=[% num %]">[[% num %]]</a>[% END %] [% END %] ### navigation like: prev 20 | next 20 [% IF pager.previous_page %] <a href="display?page=[% pager.previous_page %]"> prev [% pager.entries_per_page %]</a> | [% END %] [% IF pager.next_page %] <a href="display?page=[% pager.next_page %]"> next [% pager.entries_per_page %]</a> [% END %] NOTE
/ TODO This modules internally retrieves itertors, then creates "Data::Page" object for paging utility. Using SQL clauses "LIMIT" and/or "OFFSET" with "DBIx::Pager" might be more memory efficient. AUTHOR
Tatsuhiko Miyagawa <miyagawa@bulknews.net> Original idea by Tomohiro Ikebe <ikebe@cpan.org> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Class::DBI, Data::Page perl v5.10.0 2006-03-01 Class::DBI::Pager(3pm)
All times are GMT -4. The time now is 06:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy