0

I'm trying to make a remote mysqldump and afterwards download it with rsync which is all working good, but I also want to log the remote errors I get which I now only see in the terminal output. I mean errors like this mysqldump: Got error: 1044: Access denied for user 'root'@'localhost' to database 'information_schema' when using LOCK TABLES?

This is the important part of my code:

MYSQL_CMD="mysqldump -u ${MYSQL_USER} -p${MYSQL_PASS} $db -r /root/mysql_${db}.sql"
$SSH -p ${SSH_PORT} ${SSH_USER}@${SSH_HOST} "${MYSQL_CMD}" >> "${LOGFILE}"

In my research I only found solutions for getting the exit code and return values.

I hope someone can give me a hint, thanks in advance.

1 Answer 1

1

These error messages are being written to stderr. You can redirect this to a file using 2> or 2>> just like you do for stdout with > and >>. Eg:

ssh ... 2>/tmp/logerrors

Note there is no space between 2 and >. You can merge stderr into the same file as stdout by replacing your >> "${LOGFILE}" with

ssh ... &>> "${LOGFILE}"

Again, no space in &>, which can also be written >&.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your very detailed description this was the missing hint for my problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.