Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
email output from multiple commands
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Thu Feb 05, 2015 5:12 pm    Post subject: email output from multiple commands Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Feb 05, 2015 8:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Thu Feb 05, 2015 9:20 pm    Post subject: Reply with quote

When I do that I get:

Code:
-su: fg: %: no such job
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Feb 05, 2015 9:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Thu Feb 05, 2015 9:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Feb 05, 2015 10:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Thu Feb 05, 2015 11:06 pm    Post subject: Reply with quote

It looks like I just needed to switch the curly brackets for parenthesis, thanks Khay!
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21635

PostPosted: Thu Feb 05, 2015 11:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum