From: srikanth on
On Jun 7, 9:11 pm, Bit Twister <BitTwis...(a)mouse-potato.com> wrote:
> On Mon, 7 Jun 2010 08:37:03 -0700 (PDT), srikanth wrote:
> > How can i implement this script into my script? sorry for asking these
> > type of questions as i am poor at coding.
>
> Just an FYI. Chris's script is executed as a child/sub-process.
>
> Downside to that is your main code can hang reading a site and Chris's
> spinner will still be spinning away.
>
> My script was using a for loop to emulate your loop of reading sites.
> My ls > /dev/null was a replacement of your fetching/processing web
> site contents and allow you to see the spinner/wheel actually spinning.

Also I have one more question here... If i use xdg-open http://google.com
it was opening in a browser (user set default browser)
if i use xdg-open instead of HEAD in my script it is opening browser
with specified URL. I need to close opened browser/tab in order to
open another URL by the script. How can i solve this problem
Here is my script
#!/bin/bash
if [ -z "$1" ]
then
printf "Provide the text file location to process.\n"
exit 0
fi
{
for i in `cat $1`
do
echo "`xdg-open $i`"
done
}
exit 0

Create a text file which contains some group of URLs and provide the
location.
From: Bit Twister on
On Tue, 8 Jun 2010 02:14:28 -0700 (PDT), srikanth wrote:
<big snip>

> It is showing only
> Browsing URLs.........\

Yes, my code without the "for i in {1..100} ; do" loop was to go
inside your "for j in `cat $1`" loop.


> can you please fix my problem.

The progress indicator problem, yes. I made it into a function
so your code would be easier to read.



#!/bin/bash

if [ -z "$1" ]
then
printf "Provide the text file location to process.\n"
exit 0
fi

_wheel="|/-\\"
_c=0
_counter=0

function show_progress
{
printf "\b%s" ${_wheel:$_c:1}
let _c="_c + 1"
if [ $_c -gt 3 ] ; then
_c=0
fi

let _counter="_counter + 1"
if [ $_counter -gt 10 ] ; then
_counter=0
printf "\b.|"
fi
} # end function show_progress

#*********************************
#* main code starts here
#*********************************


printf "Browsing URLs."

{
for j in `cat $1`
do
echo "$j - `HEAD -d $j`"
show_progress
done
} > "/tmp/output.text" 2>&1

printf "\n"
#**************** end of script *************************
From: Bit Twister on
On Tue, 8 Jun 2010 02:14:28 -0700 (PDT), srikanth wrote:
>
> It is showing only
> Browsing URLs.........\

Heheh, without nothing being processed, it spun the wheel so fast
you never noticed much.


> My input text file contains 600+ urls. Does the progress bar will show
> until the script process all of my URLs?

Well, yes an no. You have redirected all output from your loop into
/tmp/output.text. Even with my change, progress indicator goes into
/tmp/output.text and no progress is shown on screen.
Suggestion with some readability changes:

printf "Browsing URLs."

for j in $(cat $1)
do
echo "$j - $(HEAD -d $j)" > /tmp/output.text 2>&1
show_progress
done

From: srikanth on
On Jun 8, 2:33 pm, srikanth <srikanth0...(a)gmail.com> wrote:
> On Jun 7, 9:11 pm, Bit Twister <BitTwis...(a)mouse-potato.com> wrote:
>
> > On Mon, 7 Jun 2010 08:37:03 -0700 (PDT), srikanth wrote:
> > > How can i implement this script into my script? sorry for asking these
> > > type of questions as i am poor at coding.
>
> > Just an FYI. Chris's script is executed as a child/sub-process.
>
> > Downside to that is your main code can hang reading a site and Chris's
> > spinner will still be spinning away.
>
> > My script was using a for loop to emulate your loop of reading sites.
> > My ls > /dev/null was a replacement of your fetching/processing web
> > site contents and allow you to see the spinner/wheel actually spinning.
>
> Also I have one more question here... If i use xdg-openhttp://google.com
> it was opening in a browser (user set default browser)
> if i use xdg-open instead of HEAD in my script  it is opening browser
> with specified URL. I need to close opened browser/tab in order to
> open another URL by the script. How can i solve this problem
> Here is my script
> #!/bin/bash
> if [ -z "$1" ]
> then
>   printf "Provide the text file location to process.\n"
>   exit 0
> fi
> {
> for i in `cat $1`
> do
> echo "`xdg-open  $i`"
> done}
>
> exit 0
>
> Create a text file which contains some group of URLs and provide the
> location.

Twister,
can i do one thing here. I will start the function in background and
do the process when first url processes then it will kill the browser
then again loop will open browser with next set of urls. Is there any
way to open in same window instead of killing it and opening it again.?
From: Bit Twister on
On Tue, 8 Jun 2010 07:39:30 -0700 (PDT), srikanth wrote:


> Twister,
> can i do one thing here. I will start the function in background and
> do the process when first url processes then it will kill the browser
> then again loop will open browser with next set of urls. Is there any
> way to open in same window instead of killing it and opening it again.?

Only kludges I can think of is find some application used to
regression test gui applications. I know it would have to feed input
into gui application to test it's functionally. No idea if "expect"
could be used to feed urls to browser.

As far as I am concerned you are using the wrong tool for what you are
trying to do. If me, I would use wget or html2text, depending on site.
I use those to fetch web pages to scan for updates to applications I
have downloaded from that site.

Snippet examples follow:

_exe=$(basename $0)
_ref_dir=/local/data/$_exe
pick_msg=(" ")

function compare_lst_ref
{
cmp -s $_lst_fn $_ref_fn
if [ $? -ne 0 ] ; then
echo "
ww ; diff -bBw $_ref_fn $_lst_fn

\cp $_lst_fn $_ref_fn

Get new $_app at $_url

Download from $_download" > $_tmp_fn

printf "%s\n" "${pick_msg[@]}" >> $_tmp_fn

echo "
This message is from /local/bin/$_exe
" >> $_tmp_fn
mail -s "$_app From $_exe" $USER < $_tmp_fn
/bin/rm $_tmp_fn
fi

} # end compare_lst_ref


#****************************************************
#* check for virtual box update
#****************************************************

_app=virtbox
_url='http://www.virtualbox.org/wiki/Linux_Downloads'
_download="$_url"
_wgt_fn=$TMPDIR/Linux_Downloads
_lst_fn=$TMPDIR/${_app}.lst
_ref_fn=$_ref_dir/Linux_Downloads_${_app}.ref
pick_msg=("Pick .i586.rpm")

rm -f ${_wgt_fn}*
wget $_url -o /dev/null
grep -i Mandriva $_wgt_fn > $_lst_fn
grep -i 'All distributions' $_wgt_fn >> $_lst_fn
compare_lst_ref

#****************************************************
#* check for java jre update
#****************************************************

_app=jre
_url='http://java.sun.com/javase/downloads/index.jsp'
_download=$_url
_lst_fn=$TMPDIR/${_app}.lst
_ref_fn=$_ref_dir/${_app}.ref
pick_msg=("Pick JRE and i586-rpm.bin")

html2text -nobs -style pretty -width 132 $_url | grep "JRE" > $_lst_fn
compare_lst_ref