11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appen<strong>di</strong>ce A. Script aggiuntivi<br />

#+ being used -- catch empty CL’s.<br />

echo "No URL’s given! You must enter them on the same line as wgetter2."<br />

echo "E.g., wgetter2 http://somesite http://anothersite."<br />

echo "Use $help option for more information."<br />

exit $E_NO_URLS # Bail out, with appropriate error code.<br />

fi<br />

URLS=" $@"<br />

# Use this so that URL list can be changed if we stay in the option loop.<br />

while [ 1 ]; do<br />

# This is where we ask for the most used options.<br />

# (Mostly unchanged from version 1 of wgetter)<br />

if [ -z $curDepth ]; then<br />

Current=""<br />

else Current=" Current value is $curDepth"<br />

fi<br />

echo "How deep should I go? (integer: Default is $depthDefault.$Current)"<br />

read Depth # Recursion -- how far should we go?<br />

inputB="" # Reset this to blank on each pass of the loop.<br />

echo "Enter the name of the referring page (default is none)."<br />

read inputB # Need this for some sites.<br />

echo "Do you want to have the output logged to the terminal"<br />

echo "(y/n, default is yes)?"<br />

read noHide # Otherwise wget will just log it to a file.<br />

case $noHide in # Now you see me, now you don’t.<br />

y|Y ) hide="";;<br />

n|N ) hide=" -b";;<br />

* ) hide="";;<br />

esac<br />

if [ -z ${Depth} ]; then # User accepted either default or current depth,<br />

#+ in which case Depth is now empty.<br />

if [ -z ${curDepth} ]; then # See if a depth was set on a previous iteration.<br />

Depth="$depthDefault" # Set the default recursion depth if nothing<br />

#+ else to use.<br />

else Depth="$curDepth" # Otherwise, set the one we used before.<br />

fi<br />

fi<br />

Recurse=" -l $Depth" # Set how deep we want to go.<br />

curDepth=$Depth # Remember setting for next time.<br />

if [ ! -z $inputB ]; then<br />

RefA=" --referer=$inputB" # Option to use referring page.<br />

fi<br />

WGETTER="${CommandA}${pattern}${hide}${RefA}${Recurse}${CookiesON}${lister}${Woptions}${U<br />

# Just string the whole lot together . . .<br />

# NB: no embedded spaces.<br />

# They are in the in<strong>di</strong>vidual elements so that if any are empty,<br />

#+ we don’t get an extra space.<br />

724

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!