LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 12:07 PM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 263

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, 12:16 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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, 12:25 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

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

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


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
[SOLVED] expect script or oneliner bravored Linux - Software 9 10-04-2016 09: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 08:25 AM
[SOLVED] Bash to ash: Help converting a script? Mouse750 Programming 7 09-08-2011 01:32 PM
[SOLVED] Converting bash script into PHP suse_nerd Programming 7 07-11-2011 05:36 AM
converting a py script to bash saawan Linux - Software 2 05-06-2009 11:56 AM

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

All times are GMT -5. The time now is 11:31 PM.

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