I wrote I simple bash script to wget an archive from iblocklist.com and extract it to my transmission blocklists dir. After it failed to run several times I found that the .gz archive being pushed by iblocklist was corrupt but the .zip was not so I decided to implement some error catching and an alternate means of accomplishing the task. After rewriting the script, I get unexpected EOF error and I cannot find where the problem lies. I’m by no means an advanced user of bash but I can usually accomplish what I want through trial and error and google. Not today. I’ve looked for the obvious missing }, fi, and ;’s but it looks good to me. Not sure if it matters but on this machine I’m running a Backtrack linux distro that more or less forces you to be root at all times. I’m a beginner so please be gentle 🙂
#!/bin/bash
function test {
"$@"
STATUS=$?
if [ $STATUS -ne 0 ]; then
echo "error with $1";
fi
return $STATUS
}
function askyn {
read -p "The operation failed. Try alternate means? [Y/n] " -n 1 -r
if [[ "$REPLY" =~ ^[Yy] ]] || [[ "$REPLY" = "" ]]; then YN=1;
else YN=0; fi
return $YN
}
function cleanup {
if [ $ALT == 0 ]; then {
test rm /root/scripts/.lvl1/dl/level1.gz
if [ $STATUS -ne 0 ]; then {
echo Removal of archive failed
}fi
}else {
test rm /root/scripts/.lvl1/dl/level1.zip
if [ $STATUS -ne 0 ]; then {
echo Removal of archive failed
}fi
}fi
return
}
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 ]; then { #wget failed first try
askyn
if [ $YN == 1 ]; then ALT=1;else exit;fi #prompt for alternate; exit if not
}else { #wget worked first try
test file-roller -e /root/.config/transmission/blocklists /root/scripts/.lvl1/dl/level1.gz
if [ $STATUS -ne 0 ]; then { #file-roller failed to extract the list
askyn
if [ $YN == 1 ]; then ALT=1;else exit;fi #prompt for alternate; exit if not
}else { #everything worked first try
echo Download and extraction successful
cleanup
}fi
}fi
if [ $ALT == 1 ]; then { #try to 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 ]; then { #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 to unzip .zip
if [ $STATUS -ne 0 ]; then { #unzip failed
echo Alternate means failed. Exiting.
exit
}else { #everything worked second try
echo Download and extraction successful using alternate means
cleanup
}fi
}fi
}fi
The problem is your use of
}fito terminate anif. The token}fiis not afi. So the shell at the end of the file has a lot of openifs missing theirfis.You are in dire need of reading the shell manual, understanding shell grammar, and asking your local shell guru. The script as written is fubar, even with the syntax errors corrected.