When automating mysqldump it is necessary to pass authentication information along with the command. While you can pass the credentials on the command line this is considered unsafe as the password would be visible to all users using the ps afx command (for example).
A workaround for this is using expect a program that is meant to automate user interaction for terminal programs. expect simulates a tty and passes input to the controlled program depending on its output.
# using a here-document to pass commands to expect.