I have the following simple shell script:
# get all servers from config
sshservers=`node $scriptDir/readconfig.js --command cluster.sshservers`
#for each server
for server in sshservers
do
#run deployserver with server (server:port format) argument
if ! sh deployserver --server $server
then
exit 1 #failure
fi
done
Now, the node command to get the sshservers may return an exit code that is nonzero. When this happens, things went horribly wrong and so I would like to quit with an error message.
How would I do this? Would this be the most appropriate way?
sshservers=`node $scriptDir/readconfig.js --command cluster.sshservers`
if ! $?
then
echo "Error: node readconfig tool failed."
exit 1
fi
Also, how do I output the stderr of this node command when things go so horribly wrong?
Finally, is the way I exit when sh deployserver fails proper, or should this be done differently?