![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Accessing variables of one shell script in another shell script | rsendhilmani | Shell Programming and Scripting | 2 | 03-17-2009 01:17 AM |
| Setting environment variable on a remote solaris machine using shell script | eamani_sun | Shell Programming and Scripting | 1 | 05-30-2008 10:05 PM |
| Shell Script Variables | ragha81 | Shell Programming and Scripting | 3 | 08-22-2006 03:43 AM |
| problem in getting the path of environment variable set in bashrc in my shell script | krithika | Shell Programming and Scripting | 8 | 05-26-2006 08:19 AM |
| help..Environment variables... | sekar sundaram | UNIX for Dummies Questions & Answers | 3 | 08-30-2005 03:35 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
shell script help: sorting, incrementing environment variables and stuff
First: me == noob. Whats a good resource for shell script info cause I'm having trouble finding good info.
I'm writing a shell script to automate the setup of a flash 'page flip'. My current code is below. the page flip takes an xml file of format HTML Code:
<content> <pages src="/path/to/image.jpg" preload="true"></pages> etc </content> 1. make folders ./xml and ./pages 2. copy the jpegs to the "./pages/param2" folder 3. Read a directory of jpegs (passed as param1) 4. build the xml file listing the files SORTED! (eg <page src="file1" preload="true"></page> <page src="file2" preload="true"></page>... <page src="file10" preload="false"></page>) 5. only set preload=true for the first X pages 6. package ./pages and ./xml into a tar then transfer it to my web server Some of the jpegs whose filenames need to be used in the xml file, have names like: PrefixIndex.jpg eg, where BRISGUIDE_JAN08 is the Prefix: BRISGUIDE_JAN08.jpg BRISGUIDE_JAN0802.jpg BRISGUIDE_JAN0803.jpg BRISGUIDE_JAN0804.jpg etc So to get it to sort properly in the xml file(eg 2.jpg comes after 1.jpg, not after 10.jpg), i was pulling the BRISGUIDE_JAN08 off and using sort -n to arrange them by their Index. but then I end up with a file called .jpg cause the first file doesn't have an index... so i thought I'd add a 0 to the start of the file. This is fine, a little ugly but the question is: maybe there is a way to get the sort command to sort a list like: Code:
page.jpg page1.jpg page10.jpg page2.jpg page3.jpg Code:
page0.jpg page1.jpg page2.jpg page3.jpg page10.jpg PLUS I can't get the counting variables working for the preload up to X working. Is there an alternative to environment variables for counting in shell scripts? Maybe this would be better in a different shell? CSH? Thanks! Code:
#!/bin/sh
if [ $# -ne 3 ]; then
echo;
echo Usage: $0 source_jpegs_folder name [prefix_to_remove]
echo EXAMPLE: $0 ./jpegs 01_2008_SEQ BRISGUIDE_JAN08
echo;
exit 127
fi
automator_path=/YYY/Projects/Pageflip/ag_automator; export automator_path;
ag_id=$2; export ag_id;
number_to_preload=6; export number_to_preload;
ag_counter=0; export ag_counter;
mkdir $automator_path/pages;
mkdir $automator_path/xml;
cd $1;
for each in *.jpg; do
cp "$each" $automator_path/pages/$(echo $each|sed "s/ /_/g")
done
echo "<content width=\"283\" height=\"595\" hcover=\"false\" transparency=\"true\">" > $automator_path/xml/$ag_id.xml
cd $automator_path/pages/
mkdir $automator_path/pages/$2;
for f in *.jpg; do
mv $f $automator_path/pages/$ag_id/
done
cd $automator_path;
cd pages/$ag_id;
for h in *.jpg; do
mv $h 0${h#$3};
done
for f in `ls *.jpg | sort -n`; do
if [ $ag_counter -lt $number_to_preload ]; then
echo "<page src=\"/pages/$2/0$f\" onLoad=\"true\" ></page>" >> $automator_path/xml/${ag_id}.xml
else
echo "<page src=\"/pages/$2/0$f\" onLoad=\"false\" ></page>" >> $automator_path/xml/${ag_id}.xml
fi
"$ag_counter" = "$ag_counter"+1;
export "$ag_counter";
done
echo "</content>" >> $automator_path/xml/$ag_id.xml;
cd $automator_path
tar -cvzf $ag_id.tar.gz xml/$ag_id.xml pages/$ag_id;
scp ./$ag_id.tar.gz admin@XXX.com:~/vhosts/XXX.com/httpdocs/work;
wait;
|
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|