Reputation: 933
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.
Upvotes: 0
Views: 63
Reputation: 12255
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 >&
.
Upvotes: 1