Be sure to use non interactive sudo (The -n option prevents sudo from prompting the user for a password)