LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-17-2024, 04:29 AM   #16
Thom1b
Member
 
Registered: Mar 2010
Location: France
Distribution: Slackware
Posts: 486

Original Poster
Rep: Reputation: 339Reputation: 339Reputation: 339Reputation: 339

Quote:
Originally Posted by Windu View Post
You are confusing '|' (the pipe symbol) with '||' (the logical OR). The script pipes the output of the "$i" command into the 'sed'. That executes every time, not only when the previous command exits with a success code.
With « $i | sed '1i\ », the name of the job is displayed only if $i return 0, I don't understand why, but it works with « $i 2>&1 | sed '1i\ »
I made many tests before posting my message, I'm 99% sure I'm right. Maybe you can test and confirm if I'm wrong or right?

Last edited by Thom1b; 01-17-2024 at 04:35 AM. Reason: Add With… line to be more specific
 
Old 01-18-2024, 09:52 AM   #17
Thom1b
Member
 
Registered: Mar 2010
Location: France
Distribution: Slackware
Posts: 486

Original Poster
Rep: Reputation: 339Reputation: 339Reputation: 339Reputation: 339
Hi,

The issue with sed is it does nothing if stdin is empty.

I think I found a not too bad fix, still not perfect. I replaced the lines 92 to 94 in /usr/bin/run-parts:
Code:
$i | sed '1i\
'"$i"':\
'
With these:
Code:
if result=$($i 2>&1); then
  [[ -n "$result" ]] && echo -e "$i finished successfully:\n\n$result"
else
  echo -e "$i finished with error(s):\n\n$result" 1>&2
fi
With this crontab:
Code:
47 * * * * /usr/bin/run-parts /etc/cron.hourly
stdout and stderr are sent by mail as expected with the name of the jobs and report if the job is done successfully or with error.

With this crontab:
Code:
47 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
a mail is sent only if a job failed but stdout and stderr are both sent.
Right now I didn't find a good way to send only stderr, but it's a start.
 
Old 01-18-2024, 10:28 AM   #18
Windu
Member
 
Registered: Aug 2021
Distribution: Arch Linux, Debian, Slackware
Posts: 594

Rep: Reputation: Disabled
Quote:
Originally Posted by Thom1b View Post
With « $i | sed '1i\ », the name of the job is displayed only if $i return 0, I don't understand why, but it works with « $i 2>&1 | sed '1i\ »
I made many tests before posting my message, I'm 99% sure I'm right. Maybe you can test and confirm if I'm wrong or right?
Well yes, if the output from "$1" is empty then the sed will still be executed but it will not output anything (the empty input results in empty output) and cron will not invoke the mailer.
If the "$1" command writes text to STDOUT, then the "sed" command will simply add a header line containing the name of the program and ending with a colon, then an empty line; and then the actual output. And that total gets emailed to you so that you know what program this is from.
 
Old 01-18-2024, 10:30 AM   #19
Thom1b
Member
 
Registered: Mar 2010
Location: France
Distribution: Slackware
Posts: 486

Original Poster
Rep: Reputation: 339Reputation: 339Reputation: 339Reputation: 339
I think about always redirecting run-parts to 1>/dev/null. Instead of, maybe we can use the /etc/default/run-parts file and specify something like "LOGLEVEL=${LOGLEVEL:-err}". I can work on it if you're interested.
 
Old 01-18-2024, 10:35 AM   #20
Thom1b
Member
 
Registered: Mar 2010
Location: France
Distribution: Slackware
Posts: 486

Original Poster
Rep: Reputation: 339Reputation: 339Reputation: 339Reputation: 339
Quote:
Originally Posted by Windu View Post
Well yes, if the output from "$1" is empty then the sed will still be executed but it will not output anything (the empty input results in empty output) and cron will not invoke the mailer.
If the "$1" command writes text to STDOUT, then the "sed" command will simply add a header line containing the name of the program and ending with a colon, then an empty line; and then the actual output. And that total gets emailed to you so that you know what program this is from.
You know what program this is from when STDOUT is not empty, you're right. If STDERR is not empty but STDOUT is, sed won't add the name of the program. That's the issue.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Updated current, symbolic link from /usr/bin/vi to /usr/bin/elvis missing? petejc Slackware 3 02-18-2020 04:48 PM
Error: Cannot find 'ssh-keygen' in '/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin' venu.navat Linux - Software 3 03-08-2012 04:00 AM
On slack-current: /usr/bin/mtp-getfile -> /tmp/package-libmtp/usr/bin/mtp-connect ? LuckyCyborg Slackware 3 05-03-2010 01:13 PM
echo $PATH = /home/g3rc4n/bin:/usr/local/bin:/usr/bin:/bin:/usr/games ? i_heart_pandas Linux - Software 7 09-18-2009 08:33 AM
/usr/bin/run-parts sulekha Ubuntu 2 02-02-2009 10:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:47 AM.

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