I am only 3 days into learning bash scripts, so bear
with me. I have encountered a problem I cannot solve
by reading tutorials.
This script produces a syntax error in the case statement
inside the function named "direction"
Code:
./nrs: line 37: syntax error near unexpected token `;;'
./nrs: line 37: `;;'
nrs is the filename of the script.
Well, here it is. Very q&d
Code:
#!/bin/bash
#
# v1.0
# This script is designed as a temporary fix for
# the internet connection dropout problem.
#
# Unitil such time as the fault can be properly
# diagnosed, this will be the fix.
#
# The network and iptables firewall should be
# reset when the connection loss is detected by
# the ping_eval() function in the script.
#
# The final script will be executed by the
# system (as a service?)as it will reside in
# /etc/rc.d/init.d/
#
## Functions ##
function ping_eval()
{
until [ $? != "0" ] # till ping returns a fail value for its exit status
do
sleep 30
ping -c 1 194.168.8.100 -w 3 # ping again
done
}
function direction()
{
case "$?" in
"0")
ping_eval()
;;
"1")
/etc/rc.d/init.d/network restart #restarts the network
/etc/rc.d/stronger_firewall-2.4 restart #restarts the firewall
;;
"2")
## /home/ian/logs/nrs/fail < cat <<- _EOF_ # will eventually print
## echo "ping has generated an error at" # the time of the exit status 2
## date # from ping when I figure out how.
## echo "the nrs has exited due to this error"
## _EOF_
exit 1 #if the ping returns an unknown error
;;
esac
}
## Commands ##
case "$1" in
start)
ping -c 1 194.168.8.100 -w 3 # ping again
until [ $? = "3" ]
do
direction()
done
exit 0
;;
*)
echo "Usage: nrs {start}"
exit 1
;;
esac
# end of script
I'm sure its something glaringly obvious but I've
gone over case statement syntax again and again,
and I just can't fathom it.
Any help would be greatly appreciated