I have the following script (at the end of the explanation and question).
There is two functions. On the first function there is a call to firefox -print extension. Everything works fine if I run it line by line.
The problem is that inside a bash script firefox is called many times in a few seconds instead of being called once at a time and waiting to finish.
I donnot would like to add a sleep in the funcion because I don't know how long can it take.
There is any way to force bash to do not launch threads? (which I suppose is doing)
Thanks.
This is my script .(it's bash and not sh because of the command let)
#!/bin/bash
####TODO###
####variables
# join files
# send with attachment
## Date, to be used as reference on tmp files
DATE=`date +%Y%m%d`
## File where all webs to report are listed
WEBSFILE="/home/marc.riera/Desktop/reports/websfile.txt"
## Where to store all the files.
WORKDIR="/home/marc.riera/Desktop/reports"
##################do not edit under this line
TMPDIR=$WORKDIR/$DATE
test -d $TMPDIR || mkdir -p $TMPDIR && echo "Create folder $TMPDIR for temporal usage"
REPORT=$WORKDIR/Report_$DATE.pdf
##firefox -print "http://fbmsgga01/ganglia/?m=cpu_report&r=month&s=descending&c=CPU+cluster&h=&sh=1&hc=4&z=small" -printmode pdf -printdelay 5 -printfile ~/Desktop/reports/test.pdf
firefoxprint (){
web2Print=$1
outputFile=$2
echo -n "printing $1 on $2"
firefox -print "$web2Print" -printmode pdf -printdelay 5 -printfile $outputFile
}
##gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=dospdf.pdf -dBATCH ganglia.pdf test.pdf
pdfjoin (){
outputFile=$1
origA=$2
origB=$3
echo -n "Joining $origA and $origB into $outputFile"
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=$outputFile -dBATCH $origA $origB
}
###################################### MAIN
#######################################
clear
COUNTER=0
for web in `cat $WEBSFILE|grep -v '^#'`
do
firefoxprint $web $TMPDIR/$COUNTER.pdf
let COUNTER+=1
done
echo "--------------------" $COUNTER
while [ $COUNTER -gt 0 ]; do
let COUNTER=COUNTER-1
pdfjoin $REPORT $REPORT $TMPDIR/$COUNTER.pdf
done
echo "done"
exit 0