Your script is working perfectly on my dahua nvr , to get other channels just modify http://$ip:$port/cgi-bin/snapshot.cgi?channel=1?1
channel 0 is camera 1
channel 1 is camera ...