Hello script guru's
as i write more and more code i always block at managing output... either writing to standard out, writing to files via std out (log, temp file, etc). Don't get me wrong 99% of the time it DOES the job but maybe there is more efficient.
I'm writing a small script to help production use DNS dynamic updates (named.conf 400 lines with 300 zones so i can't fuckup) and main function goes like this:
nsupdate_ops() {
echo "Start NSUPDATE File creation"
local TEMPFILE=$(mktemp /tmp/nsupdate.XXXXXX)
exec 7> ${TEMPFILE}
#echo "server ${DNSSERVER}" >&7
#echo "zone ${FWDZONE}" >&7
case ${OPERATION} in
add_rec|update_rec)
printf "server %s\nzone %s\nupdate delete %s A\nupdate add %s 3600 A %s\nsend\n", ${DNSSERVER} ${FWDZONE} ${CN} ${CN} ${ADDRESS} >&7
;;
remove_rec)
echo "update delete ${CN}. A" >&7
;;
add_cname)
echo "prereq nxrrset ${CN} A" >&7
echo "prereq nxrrset ${CN} CNAME" >&7
echo "update add ${CN}. 3600 CNAME ${CNAME}" >&7
;;
remove_cname)
echo "update delete ${CN}. 3600 CNAME ${CNAME}" >&7
;;
esac
# echo "send" >&7
exec 7>&-
echo "END NSUPDATE File creation"
}
As you can see i use echo's to std out and fd7 and printf.
I could always use a variable to my long line to make my code tidier but my main question is... is there ANY advantages to using one or another?
Is it a question of background as printf users usually means they did C?
I didn't use any:
cat >$TEMPFILE <<EOF
server $DNSSERVER
zone $FWDZONE
update delete ${CN}. A
update add ${CN}. 3600 A $ADDRESS
show
send
EOF
As i would have to do one block for each occurences.
I also didn't start to touch logging... is there a definate standard in the coding community for the use of /* insert best coding practice for script logging */ ?
Any ideas at making my code more efficient?