My script looks like:
trap "$(pwd)/dd-destroy.sh $l-env;$(pwd)/dd-drop.sh $l-db;exit" INT QUIT TERM EXIT
./dd-all.sh $l $l-db $l-env || exit 1
app_ip=$(./dd-status.sh ip $l-env|grep docker-app|awk '{print $3}')
url=http://$app_ip:8080/app/
wget -O /dev/null $url || (echo "access $url failed" && false) || exit 1
Now I want this trap launch when error occurs, those 'exit 1' (I can change them there). But when nothing happens, like dd-all.sh worked fine, when wget came fine. I do not want to call for destroy.
Can I accomplish this with trap? It's not my script, I need to change it a little. Maybe trap is a bad call here?
trap
specifies which signals thedd-destroy.sh...
command should be invoked on. I don't know of any way for that command to test what the error code was when getting anEXIT
signal. I'd recommend creating a function that has yourdd-destroy.sh ...
stuff in it; have thetrap
line invoke that function but omit the signalEXIT
; and replace yourexit 1
with{ that_function; exit 1; }
.EXIT
in thetrap
specification if you don't want the trap to run on exit?