LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-12-2016, 01:07 PM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 197

Rep: Reputation: 3
converting a bash script to a oneliner


I am having difficulties converting this bash script to a oneliner.

Code:
{
    echo Subject: This is the logfile
    cat /tmp/logfile
} | ssmtp my@email.com
I tried a few things, but every time either the subject or log file are not included in the the email.

How can I do this?
 
Old 10-12-2016, 01:16 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,362

Rep: Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001
Pretty much just by changing the newlines to semicolons.
Code:
{ echo Subject: This is the logfile; cat /tmp/logfile; } | ssmtp my@email.com
Blindly converting would leave you with one extraneous semicolon preceding the "echo" command.
 
Old 10-12-2016, 01:25 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
You can cat stdin with logfile
Code:
echo Subject: This is the logfile | cat - /tmp/logfile | ssmtp my@email.com
 
Old 10-12-2016, 01:35 PM   #4
aristosv
Member
 
Registered: Dec 2014
Posts: 197

Original Poster
Rep: Reputation: 3
both suggestions worked. thanks guys.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] expect script or oneliner bravored Linux - Software 9 10-04-2016 10:39 AM
[SOLVED] Converting Script from Linux (GNU) Bash 4 to Solaris Bash 2.05 - Any cheat sheet? oly_r Solaris / OpenSolaris 6 05-03-2013 09:25 AM
[SOLVED] Bash to ash: Help converting a script? Mouse750 Programming 7 09-08-2011 02:32 PM
[SOLVED] Converting bash script into PHP suse_nerd Programming 7 07-11-2011 06:36 AM
converting a py script to bash saawan Linux - Software 2 05-06-2009 12:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:30 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration