capture error messages in bash script and write to logfile
by Tombar from LinuxQuestions.org on (#59JK9)
Hi,
I am executing the following command in a bash script:
Code:#!/bin/bash
rclone move "${backupdir}/${fileNameBackupDbGPG}" onedrive:backupAs an error message I get the following on the console:
Code:2020/10/27 07:21:37 Failed to create file system for "onedrive:backup": failed to get root: Get "https://graph.microsoft.com/v1.0/drives/2d 1100dc776d3149/root": x509: certificate is valid for osmc, not graph.microsoft.comBut now I want to send this error to a logfile. I tried the following:
Code:#!/bin/bash
function backup_log {
echo "$(date -Iseconds) $1" >> $logfile
VAR=$(rclone move "${backupdir}/${fileNameBackupDbGPG}" onedrive:backup 2>&1)
backup_log $VAR
}But this does only partly work. I only get the first part of the error. Everything after the date (separated by space) is not captured
Code:2020-10-27T07:20:20+01:00 2020/10/27How can I modify the statement to get the full error string?
Thanks a lot.
Tombar


I am executing the following command in a bash script:
Code:#!/bin/bash
rclone move "${backupdir}/${fileNameBackupDbGPG}" onedrive:backupAs an error message I get the following on the console:
Code:2020/10/27 07:21:37 Failed to create file system for "onedrive:backup": failed to get root: Get "https://graph.microsoft.com/v1.0/drives/2d 1100dc776d3149/root": x509: certificate is valid for osmc, not graph.microsoft.comBut now I want to send this error to a logfile. I tried the following:
Code:#!/bin/bash
function backup_log {
echo "$(date -Iseconds) $1" >> $logfile
VAR=$(rclone move "${backupdir}/${fileNameBackupDbGPG}" onedrive:backup 2>&1)
backup_log $VAR
}But this does only partly work. I only get the first part of the error. Everything after the date (separated by space) is not captured
Code:2020-10-27T07:20:20+01:00 2020/10/27How can I modify the statement to get the full error string?
Thanks a lot.
Tombar