The Humble Rat
The Humble Rat

Reputation: 4696

Append message before Sending / Concatenate Commands - Bash

Firstly apologies for the title, I am sure it is not the clearest.

I am in the process of installing tripwire on a server which is working perfectly fine. When running the following command, I receive the Tripwire report.

sudo tripwire --check | mail -s "Tripwire report for `uname -n`" [email protected]

I am planning to save these reports as post on a Wordpress site, so that reports can be easily found and date recorded. Wordpress has the ability to post by email using an address you set up specifically for this purpose. When sending the Tripwire report to the email I have set up, the Post is successfully created in a default category specified. Using a cron job, this means everything is nearly in place for automated file change detection and Wordpress posting.

I am using the following plugin: http://wordpress.org/plugins/post-by-email/

this allows you to use shortcode in the email to specify a category. Therefore in the email if I put say [category 3] in the body it will post the report in Category 3, which is what I need. I plan to have multiple servers posting to the site via the post by email, each one appending a different category in the message body, so that a category represents a server and by looking at the category you can see in date order the Tripwire reports.

The issue I am having is appending the shortcode to the message.

I have tried the following:

sudo <(tripwire --check) | <(echo successfullyappended) | mail -s "Tripwire report for `uname -n`" [email protected]

This was suggested by the following: How do i append some text to pipe without temporary file However, I only receive the echoed text not the report.

I have also tried the following:

sudo <(tripwire --check) & <(echo successfullyappended) | mail -s "Tripwire report for `uname -n`" [email protected]

and

sudo tripwire --check & echo successfullyappended | mail -s "Tripwire report for `uname -n`" [email protected]

I can't pin point where I found these snippets, but regardless, they also do not work. Effectively they just run this part of the command:

sudo tripwire --check

Can someone please guide me in the right direction to appending this text onto the end of the report. I have literally done everything necessary bar this small bit, that has taken me more time than the whole set up of the site etc has!!

Any help is much appreciated.

Upvotes: 0

Views: 110

Answers (1)

chepner
chepner

Reputation: 531848

You can use a command group to concatenate the standard output of multiple commands into one stream:

{
    sudo tripwire --check
    echo successfullyappended
} | mail -s "Tripwire report for $(uname -n)" [email protected]

Upvotes: 2

Related Questions