Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Shell Script to read hive table and send email Post 303042230 by Mi4304 on Thursday 19th of December 2019 10:21:18 AM
Old 12-19-2019
Shell Script to read hive table and send email

HI Team,
I am working on reading hive table and send email in email body using shell script, can you please help on fixing the errors: I have 6 columns in my hive table and trying to send the email in the mail body.
below script:

Code:
#!/bin/bash
hive -e 'SELECT count(*) from db.table' > output.txt
sed -i 's/\t/,/g' $tmp/output.txt

nawk BEGIN{
FS=","
print  "MIME-Version: 1.0"
print  "Content-Type: text/html"
print  "Content-Disposition: inline"
print  "<HTML>""<TABLE border="1"><TH>TB1</TH><TH>TB2</TH><TH>TB3</TH><TH>TB4</TH><TH>TB5</TH><TH>TB6</TH>" }
 {
printf "<TR>"
for(i=1;i<=NF;i++)
printf "<TD>%s</TD>", $i
print "</TR>"
 }
END{
print "</TABLE></BODY></HTML>"
 }
file-to-convert.csv > file.html
echo "output.txt" | mailx -s "output" -a output.txt email.com

--- Post updated at 04:21 PM ---

getting below error:

Code:
Java HotSpot(TM) 64-Bit Server VM warning: Using the ParNew young collector with the Serial old collector is deprecated and will likely be removed in a future release
OK
Time taken: 4.722 seconds, Fetched: 5 row(s)
Waiting for Tez session and AM to be ready...
sed: can't read $tmp/output.csv: No such file or directory
./countemail.sh: line 18: nawk: command not found
./countemail.sh: line 19: output1.csv: command not found


Last edited by Neo; 12-19-2019 at 12:13 PM.. Reason: Code Tags Please See YT Video on this: https://youtu.be/4BuPvWJV__k
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write a shell script to send an email to an id

Hi all, I want to know how to send an email using shell script ..... I tried a command call mail but it did not work.. Please any one reply.. With example if you know thanks.. Madhu (4 Replies)
Discussion started by: madhumathikv
4 Replies

2. Shell Programming and Scripting

make un shell script to send email

Hi, Someone Knows how to obtein a chain from a unix file, but not all the line, for exemple, for this file ,obtein only 902111111 and to keep the value, this value will be used to make a mailx. NF=ALL, SUBJ= FROM: SN=CD, SE=TOPCALL, NA=, N=902111111, N=TCLFI TO: SE=FAX, NA=, C1=... (0 Replies)
Discussion started by: peybol
0 Replies

3. Shell Programming and Scripting

How to send email through shell script

Hi All, I am new to the unix , i have to deliver one script very urgently I have to write a shell script where i have i want to send email to specific email id in this script i want FROM to be parameterized and stored in a variable TO to be parameterized and stored in a variable... (3 Replies)
Discussion started by: nileshbhawsar
3 Replies

4. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

5. Shell Programming and Scripting

How to read specific line of text from a Script and send email notification

Hi ! I am a newbie and never officially wrote a shell script before. The requirement for this script is : 1) Read a file called 'bpm.log' and identify if it has a specific text such as 'this is the text'. Its a static value and that is the only text we need to read. 2) If that... (2 Replies)
Discussion started by: atechcorp
2 Replies

6. Shell Programming and Scripting

Shell script to send an email from the txt file

Hi Friends, Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file. text file contains the no. of records like: giridhar 224285 847333 giridhar276@gmail.com ramana 84849 33884 venkata.ramana@gmail.com... (6 Replies)
Discussion started by: giridhar276
6 Replies

7. Shell Programming and Scripting

Help with shell script to send email once

Hi Guys, I have this script which will monitor oracle db process if up or down.And I want it to send email if it's down and the time it's back to online. However my script just keep on sending "Email Up" if the db is up or "Email Down" if the db is down.Is there any way to trap it so that it... (5 Replies)
Discussion started by: d3xt3r
5 Replies

8. Shell Programming and Scripting

how to send html email from shell script

This is my below script which is working fine as it send only plain text email. So My question is- How can I modify my below script to send this as an HTML formatted email? I want to show the text color of this expression `(echo "100*$TEST2/$TEST1" | bc -l)` as `RED` in an email and that can be... (3 Replies)
Discussion started by: raihan26
3 Replies

9. Shell Programming and Scripting

Shell scripting unable to send the sql query data in table in body of email

I have written a shell script that calls below sql file. It is not sending the query data in table in the body of email. spool table_update.html; SELECT * FROM PROCESS_LOG_STATS where process = 'ActivateSubscription'; spool off; exit; Please use code tags next time for your code and data.... (9 Replies)
Discussion started by: Sharanakumar
9 Replies

10. Solaris

How to output the prstat into table and send through email?

Hi how to send below prstat script output into table format and send through email? prstat|awk '{ if ($9 >= 5) print $0 }' (17 Replies)
Discussion started by: tharmendran
17 Replies
DACSEMAIL(1)						       DACS Commands Manual						      DACSEMAIL(1)

NAME
dacsemail - Simple outgoing email agent SYNOPSIS
dacsemail [-bcc addr] [{-bf | --bodyfile} path] [{-bs | --bodystring} string] [-cc addr] [-ct value] [{-f | --from} from] [-h | --help] [-header name value] [{-mailer | -mta} path] [{-mailer-flags | -mta-flags} string] [-p | --prompt] [-save path] [{-s | --subject} subject] [-sender sender] [{-t | --to} addr] [-transform] [-v | --verbose] [-var name value] DESCRIPTION
This program is part of the DACS suite. The dacsemail utility is a simple agent for sending email messages. It is a stand-alone program that neither accepts the usual DACS command line options (dacsoptions[1]) nor accesses any DACS configuration files. dacsemail constructs an RFC 822[2] format message but does not transmit it. It requires an external mailer, such as sendmail(8)[3], to transfer the message. The mailer command and its arguments can be specified on the dacsemail command line (see -mailer) or at build time (see dacs.install(7)[4]). OPTIONS
If the source for the message body is not specified on the command line, it will be read from the standard input. At least one recipient must be specified using -t, -cc, or -bcc. -bcc addr Send the message to the undisclosed recipient address addr. It is the responsibility of the mailer to delete these recipient addresses before transmitting the message. This flag may be repeated. -bf path --bodyfile path Read the message body from path. If path is -, the standard input is read. -bs string --bodystring string Use string as the message body. -cc addr Send the message to recipient addr as a carbon copy. This flag may be repeated. -ct value Add a Content-type header of MIME type value to the message. If value is multipart/alternative, an appropriate boundary variable will be created, unless one has already been specified on the command line with the -var flag. It is assumed that the message body has already been correctly formatted for this MIME type, or will be after it has been transformed (see -transform). -f from --from from Use from as the value of the message's From header. -h --help Print usage information and then exit. -header name value Add a message header named name with value value. This flag should only be used for headers that do not have specific flags (-t, -ct, -f, and so on). -mailer path -mta path Use the message transfer agent command path (a full pathname) instead of the configured program. This program must read the message from its standard input and extract the list of recipients from the message's To, Cc, and Bcc headers. (If such a mailer is unavailable, it will be necessary to write a small program to wrap a mailer and provide the required interface to dacsemail.) The default is to run sendmail(8)[3] with its -t flag. -mailer-flags string -mta-flags string Regardless of the mailer, use string for its command line flags. -p --prompt Just before the message is to be sent, display it (to stderr) and wait for the user to respond to a prompt. At the prompt, the user may abort the message or allow it to be sent. -save path Just before sending (or prompting), write a copy of the outgoing message to path, replacing any previous contents of the file. -s subject --subject subject Set the message's Subject header to subject. -sender sender Set the message's Sender header to sender. -t addr --to addr Add addr as a "To" recipient. This flag may be repeated. -transform The message body, regardless of how it is specified, is filtered through the DACS transformation function. Please refer to dacs_transform(8)[5] for details. No access control rules may be associated with any transformation; i.e., they are all unconditional. A similar effect can be obtained by piping the output of dacstransform(1)[6] into dacsemail. -v --verbose Enable verbose output for debugging. -var name value Create a variable[7] named name set to value for the transform function. The variable's value can be referenced within the message body in the DACS namespace as ${DACS::name}. The variable must not already be defined. EXAMPLES
Suppose the myfile contains the following text: <!--DACS expand="*" --> This is a multi-part message in MIME format. --${DACS::boundary} Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 7bit Hello, ${DACS::user}! --${DACS::boundary} Content-Type: text/html; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 7bit <p> <font color="red">Hello, ${DACS::user}!</font> </p> --${DACS::boundary}-- <!--DACS end="*" --> The following command might be used to send a message with a multipart/alternative structured body: % dacsemail -ct multipart/alternative -f auggie@example.com -t harley@example.com -s "Hello" -transform -var user Auggie -bf myfile The resulting message will look something like the following: To: harley@example.com From: auggie@example.com Subject: Hello Content-type: multipart/alternative; boundary="_----------=_03885942562898683484" Date: Wed, 07 Apr 2010 16:48:41 -0700 (PDT) Content-transfer-encoding: 7bit X-mailer: DACS 1.4.24a This is a multi-part message in MIME format. --_----------=_03885942562898683484 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 7bit Hello, Auggie! --_----------=_03885942562898683484 Content-Type: text/html; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 7bit <p> <font color="red">Hello, Auggie!</font> </p> --_----------=_03885942562898683484-- FILES
None. DIAGNOSTICS
The program exits 0 if everything was fine, 1 if an error occurred. Error messages are printed to stderr. Errors and routine messages from the mailer are recorded wherever they usually logged, outside of DACS BUGS
This program's primary purpose is for testing DACS functionality that is needed for internal purposes. No significant improvements are envisioned. You could throw a rock and hit a better email agent. SEE ALSO
dacs.exprs(5)[8], dacs.install(7)[4], dacs_transform(8)[5], sendmail(8)[3] AUTHOR
Distributed Systems Software (www.dss.ca[9]) COPYING
Copyright2003-2012 Distributed Systems Software. See the LICENSE[10] file that accompanies the distribution for licensing information. NOTES
1. dacsoptions http://dacs.dss.ca/man/dacs.1.html#dacsoptions 2. RFC 822 http://www.rfc-editor.org/rfc/rfc822.txt 3. sendmail(8) http://www.freebsd.org/cgi/man.cgi?query=sendmail&apropos=0&sektion=8&manpath=FreeBSD+9.0-RELEASE&format=html 4. dacs.install(7) http://dacs.dss.ca/man/dacs.install.7.html#configure_options 5. dacs_transform(8) http://dacs.dss.ca/man/dacs_transform.8.html 6. dacstransform(1) http://dacs.dss.ca/man/dacstransform.1.html 7. a variable http://dacs.dss.ca/man/dacs.exprs.5.html#variable_syntax 8. dacs.exprs(5) http://dacs.dss.ca/man/dacs.exprs.5.html#transform 9. www.dss.ca http://www.dss.ca 10. LICENSE http://dacs.dss.ca/man/../misc/LICENSE DACS 1.4.27b 10/22/2012 DACSEMAIL(1)
All times are GMT -4. The time now is 12:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy