I am writing a bash script that reads the results of an sql query in which the results are output as HTML (using the -H option) to a file (using the -o option) and then sends those results in an email. When the results are output to the file, they come out as:
'<IDLE>'
But when I parse them from the output file they show up in the email as:
<IDLE>
Can anyone help me format these so I get the actual characters and not the entity representation?
EDIT: The way I am sending the text now is:
echo -e $EMAIL_TXT | mail -s $SUBJECT $RECIPIENT
And the way I am extracting the text from the html file ($OUT_FILE) is:
QRY_LINE=$(sed "${QRY_LNUM}q;d" $OUT_FILE)
I ended up just using string replace to replace all <s and >s with < and > respectively.
Related
I have a script that sends an email with curl. For example:
name="John"
curl...
I have a text file for my email template. The template will have the $name variable in it. For example:
Hello, $name. This is a test.
The curl part is fine but the problem is that it sends Hello, $name. This is a test instead of Hello, John. This is a test. I'm not sure how to do this. I've tried to search how to do it but I'm not even sure how to phrase the question. I keep turning up stuff on reading variables values from a files which isn't what I'm looking to do.
This fixed my issue:
eval message=$(cat test.txt) | echo $message| curl --netrc-file "/config/.netrc" --ssl-reqd --mail-from "<myemail#gmail.com>" --mail-rcpt "<youremail#gmail.com>" --url smtps://smtp.gmail.com:465 -T -
I'm using the following command to email the content a file from the shell:
mail -s 'Subject' to#domain.ext < file.txt
I always got a plain text mail with empty body and an attachment named "Subject.txt.dat" containing the content of file.txt.
I would like to get a plain text mail with the content of file.txt as body, and no attachments.
All tutorials I've found on Google suggests to use such command but in my case is not working as expected.
I'm on CentOS 6 and
man mail
shows it is using mailx.
This page seems to match your problem and offers some solutions:
https://access.redhat.com/solutions/1136493
Remove non-US-ASCII or non-printable characters from the e-mail text, or
use sendmail, which will accept and forward DOS-style formatted text, or
use mutt, which provides more funcionality regarding how the e-mail should be sent.
I'm trying to convert fastq to fasta without doing a quality filter first. When I try to use fastx toolkit to run this conversion, it gives me an error message when it runs into a low quality base and terminates the conversion so that my converted output ends very early. (error says something like quality score below -30).
I then tried to use a sed solution posted earlier on this forum about how to convert to fasta using sed. The line was this:
sed -n '1~4s/^#/>/p;2~4p'
the line I input to the terminal was:
sed -n '1~4s/^#/>/p;2~4p' Sample_As_L001_R1.cat.fastq
It spit out what I wanted, but printed directly into the terminal.
How do I get this info to not print on the terminal, but to print to an output file?
How do I specify the file/file name that I want the output to go into. Thanks.
redirect it to a file
sed -n '1~4s/^#/>/p;2~4p' Sample_As_L001_R1.cat.fastq > Sample_As_L001_R1.cat.fasta
I have a shell script like this. The purpose of this script is to tail+head out a certain amount of data from file.csv and then send it to email Bob#123.com. DataFunction seems to work fine alone however when I try to call DataFunction within the email function body. It seems it sends a empty email with the correct Title and destination. The body of the email is missing which should be the data from DataFunction. Is there a workaround for this ? Thank you in advance.
#!/bin/bash
DataFunction()
{
tail -10 /folder/"file.csv" | head -19
}
fnEmailFunction()
{
echo ${DataFunction}| mail -s Title Bob#123.com
}
fnEmailFunction
You are echoing an unset variable, $DataFunction (written ${DataFunction}), not invoking the function.
You should use:
DataFunction | mail -s Title Bob#123.com
You may have been trying to use:
echo $(DataFunction) | mail -s Title Bob#123.com
but that is misguided for several reasons. The primary problem is that it converts the 10 lines of output from the DataFunction function into a single line of input to mail. If you enclosed the $(DataFunction) in double quotes, that would preserve the 'shape' of the input, but it wastes time and energy compared to running the command (function) directly as shown.
Try this:
mail -s "Title" "bob#123com" <<EOF
${DataFunction}
EOF
I tried #0xAX's answer and couldnt get it to work properly within a bash script. You simply need to save the output of DataFunction() in some variable. You can simply use these three lines to achieve this.
#!/bin/bash
VAR1=`tail -10 "/folder/file.csv" | head -19`
echo $VAR1 | mail -s Title Bob#123.com
I´m executing the following command "grep bruno < bash.txt " which gives me the right output "bruno" and garbage "\f0\fs24 \cf0".
I´m on the command shell on a Mac OS X v10.6.8 and i´m pretty sure i should be getting the line of the found word and the word. Not garbage.
This is the Output:
Mobile-Devs-MacBook-Pro:Screenshots Poupe mdev$ grep bruno < bash.txt
\f0\fs24 \cf0 bruno\
In bash.txt i only have written "bruno", if i output with "cat bash.txt" it also gives me the following garbage:
Mobile-Devs-MacBook-Pro:Screenshots Poupe mdev$ cat bash.txt
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
\f0\fs24 \cf0 bruno\
If i make "echo bruno > bash.txt" and then "cat bash.txt" it gives me a clean output. Why am i not seeing a clean output when i write the file by hand?
Your file isn't a plain text file. It is RTF. grep is giving you the line containing "bruno", along with the rich text formatting.
When you do:
echo bruno > bash.txt
bash.txt contains only "bruno".
When you "edit the file by hand", your editor is saving as RTF. You need to save as plain text.
That isn't a plain text file. That looks like an RTF. Grep only understands text and its job is to output the entire line where the search text is found.
I cannot tell from your formatting, but I have to believe the "garbage" you are seeing is on the same line as the "bruno" text.
As others have pointed out, the problem is that the file is in RTF format, and contains formatting information. If you want to create a plain text file in TextEdit, use the menu option Format > Make Plain Text before saving it. Better yet, don't use TextEdit at all -- my favorite for plain text editing is TextWrangler, but there are plenty of other options.