Tuesday, 15 March 2011

linux - Bash unexpected EOF in my script to wget an archive and extract it, using error checking functions -



linux - Bash unexpected EOF in my script to wget an archive and extract it, using error checking functions -

i wrote simple bash script wget archive iblocklist.com , extract transmission blocklists dir. after failed run several times found .gz archive beingness pushed iblocklist corrupt .zip not decided implement error catching , alternate means of accomplishing task. after rewriting script, unexpected eof error , cannot find problem lies. i'm no means advanced user of bash can accomplish want through trial , error , google. not today. i've looked obvious missing }, fi, , ;'s looks me. not sure if matters on machine i'm running backtrack linux distro more or less forces root @ times. i'm beginner please gentle :)

#!/bin/bash function test { "$@" status=$? if [ $status -ne 0 ]; echo "error $1"; fi homecoming $status } function askyn { read -p "the operation failed. seek alternate means? [y/n] " -n 1 -r if [[ "$reply" =~ ^[yy] ]] || [[ "$reply" = "" ]]; yn=1; else yn=0; fi homecoming $yn } function cleanup { if [ $alt == 0 ]; { test rm /root/scripts/.lvl1/dl/level1.gz if [ $status -ne 0 ]; { echo removal of archive failed }fi }else { test rm /root/scripts/.lvl1/dl/level1.zip if [ $status -ne 0 ]; { echo removal of archive failed }fi }fi homecoming } alt=0 yn=-1 test wget "http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz" -o /root/scripts/.lvl1/dl/level1.gz if [ $status -ne 0 ]; { #wget failed first seek askyn if [ $yn == 1 ]; alt=1;else exit;fi #prompt alternate; exit if not }else { #wget worked first seek test file-roller -e /root/.config/transmission/blocklists /root/scripts/.lvl1/dl/level1.gz if [ $status -ne 0 ]; { #file-roller failed extract list askyn if [ $yn == 1 ]; alt=1;else exit;fi #prompt alternate; exit if not }else { #everything worked first seek echo download , extraction successful cleanup }fi }fi if [ $alt == 1 ]; { #try wget .zip test wget "http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=zip" -o /root/scripts/.lvl1/dl/level1.zip if [ $status -ne 0 ]; { #wget of .zip failed echo alternate means failed. exiting. exit }else { #wget of .zip worked test unzip -o -d /root/.config/transmission/blocklists /root/scripts/.lvl1/dl/level1.zip #try unzip .zip if [ $status -ne 0 ]; { #unzip failed echo alternate means failed. exiting. exit }else { #everything worked sec seek echo download , extraction successful using alternate means cleanup }fi }fi }fi

the problem utilize of }fi terminate if. token }fi not fi. shell @ end of file has lot of open ifs missing fis.

you in dire need of reading shell manual, understanding shell grammar, , asking local shell guru. script written fubar, syntax errors corrected.

linux bash eof

No comments:

Post a Comment