View previous topic :: View next topic |
Author |
Message |
grant123 Veteran
Joined: 23 Mar 2005 Posts: 1080
|
Posted: Thu Feb 05, 2015 5:12 pm Post subject: email output from multiple commands |
|
|
I was hoping to use this code to get the output of all 3 commands emailed to me, but only the output from the last command appears in the email. Does anyone know why?
Code: | glsa-check -t all ; emerge -pvDuN world ; emerge -p --depclean 2>&1| mail $MAILTO |
|
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Thu Feb 05, 2015 8:09 pm Post subject: |
|
|
grant123 ... something like:
Code: | % {echo 1 ; echo 2 ; echo 3} | mail -s test root |
Code: | Date: Thu, 5 Feb 2015 21:05:05 +0100 (CET)
From: khayyam@aporia.localdomain
To: root@aporia.localdomain
Subject: test
Return-Path: <khayyam@aporia.localdomain>
1
2
3 |
best ... khay |
|
Back to top |
|
|
grant123 Veteran
Joined: 23 Mar 2005 Posts: 1080
|
Posted: Thu Feb 05, 2015 9:20 pm Post subject: |
|
|
When I do that I get:
Code: | -su: fg: %: no such job |
|
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Thu Feb 05, 2015 9:47 pm Post subject: |
|
|
grant123 wrote: | When I do that I get:
Code: | -su: fg: %: no such job |
|
grant123 ... the '%' was the shell prompt, so not to be included in the command ...
best ... khay |
|
Back to top |
|
|
grant123 Veteran
Joined: 23 Mar 2005 Posts: 1080
|
Posted: Thu Feb 05, 2015 9:51 pm Post subject: |
|
|
Oh whoopsie, I always get a # or $ for the prompt. Anyway, I get this:
Code: | { echo 1 ; echo 2 ; echo 3 } | mail -s test root
> |
I think it's waiting for input. |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Thu Feb 05, 2015 10:54 pm Post subject: |
|
|
grant123 wrote: | Oh whoopsie, I always get a # or $ for the prompt. |
grant ... yes, and for zsh it's '#' and '%'
grant123 wrote: | Anyway, I get this:
Code: | { echo 1 ; echo 2 ; echo 3 } | mail -s test root
> |
I think it's waiting for input. |
oh ... I'd assumed this would work exactly the same for bash, in zsh '{ }' is a subshell. The ">" seems to be mail waiting for you to provide the body of the msg (which should come from the pipe). I'm really not sure what the problem is here, perhaps a bash user can provide an explanation.
BTW, the above works for me exactly as shown.
best ... khay |
|
Back to top |
|
|
grant123 Veteran
Joined: 23 Mar 2005 Posts: 1080
|
Posted: Thu Feb 05, 2015 11:06 pm Post subject: |
|
|
It looks like I just needed to switch the curly brackets for parenthesis, thanks Khay! |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21635
|
Posted: Thu Feb 05, 2015 11:19 pm Post subject: |
|
|
When using bash, you need a semicolon after the last command before the end of the braced expression: { echo a; echo b; echo c; } | mail.
As for the original question, it does exactly what you told it to do. It runs three command sequences:- glsa-check -t all
- emerge -pvDuN world
- emerge -p --depclean 2>&1| mail $MAILTO
Only the third sequence has its output redirected. The first two print to stdout of the calling shell. |
|
Back to top |
|
|
|