LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-27-2020, 02:28 AM   #1
Tombar
LQ Newbie
 
Registered: Oct 2020
Posts: 6

Rep: Reputation: Disabled
capture error messages in bash script and write to logfile


Hi,

I am executing the following command in a bash script:

Code:
#!/bin/bash

rclone move "${backupdir}/${fileNameBackupDbGPG}" onedrive:backup
As 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.com
But 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/27
How can I modify the statement to get the full error string?

Thanks a lot.
Tombar

Last edited by Tombar; 10-27-2020 at 01:07 PM.
 
Old 10-27-2020, 03:59 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,598

Rep: Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116
use $* instead of $1
but you can redirect the output of rclone into the log file, do not need to use any variable.
 
1 members found this post helpful.
Old 10-27-2020, 04:26 AM   #3
Tombar
LQ Newbie
 
Registered: Oct 2020
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks a lot. Yes this is working. I looked at the wrong part of the script. I always tested around the line where I execute the command but missed that the problem actually was with the function that writes the logfile.
 
Old 10-27-2020, 04:58 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,598

Rep: Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116Reputation: 5116
you are welcome
please mark the thread solved if you think your problem is solved.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script, sftp script logfile not showing transfer information enid Linux - General 3 08-15-2016 11:12 AM
Shell scripting: Print output to logfile, error to logfile & screen stefanlasiewski Programming 18 05-22-2008 01:47 PM
need help to under stand infomation in messages logfile jmeyer95 Linux - Newbie 1 07-12-2007 02:22 PM
cron job runs but will not write to logfile c_curtis Linux - General 10 06-30-2006 10:25 AM
iptable messages in logfile for blocked requests to my ip adress LiNuXkOlOnIe Linux - Networking 7 12-29-2005 02:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration