Article 59JK9 capture error messages in bash script and write to logfile

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.
Tombarlatest?d=yIl2AUoC8zA latest?i=R3s2592HKvo:uFRGzEtEbpE:F7zBnMy latest?i=R3s2592HKvo:uFRGzEtEbpE:V_sGLiP latest?d=qj6IDK7rITs latest?i=R3s2592HKvo:uFRGzEtEbpE:gIN9vFwR3s2592HKvo
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments