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
Email::MIME(3pm)					User Contributed Perl Documentation					  Email::MIME(3pm)

NAME
Email::MIME - Easy MIME message parsing. VERSION
version 1.910 SYNOPSIS
use Email::MIME; my $parsed = Email::MIME->new($message); my @parts = $parsed->parts; # These will be Email::MIME objects, too. my $decoded = $parsed->body; my $non_decoded = $parsed->body_raw; my $content_type = $parsed->content_type; ...or... use Email::MIME::Creator; use IO::All; # multipart message my @parts = ( Email::MIME->create( attributes => { filename => "report.pdf", content_type => "application/pdf", encoding => "quoted-printable", name => "2004-financials.pdf", }, body => io( "2004-financials.pdf" )->all, ), Email::MIME->create( attributes => { content_type => "text/plain", disposition => "attachment", charset => "US-ASCII", }, body_str => "Hello there!", ), ); my $email = Email::MIME->create( header_str => [ From => 'casey@geeknest.com' ], parts => [ @parts ], ); # nesting parts $email->parts_set( [ $email->parts, Email::MIME->create( parts => [ @parts ] ), ], ); # standard modifications $email->header_str_set( 'X-PoweredBy' => 'RT v3.0' ); $email->header_str_set( To => rcpts() ); $email->header_str_set( Cc => aux_rcpts() ); $email->header_str_set( Bcc => sekrit_rcpts() ); # more advanced $_->encoding_set( 'base64' ) for $email->parts; # Quick multipart creation my $quicky = Email::MIME->create( header_str => [ From => 'my@address', To => 'your@address', ], parts => [ q[This is part one], q[This is part two], q[These could be binary too], ], ); print $email->as_string; DESCRIPTION
This is an extension of the Email::Simple module, to handle MIME encoded messages. It takes a message as a string, splits it up into its constituent parts, and allows you access to various parts of the message. Headers are decoded from MIME encoding. METHODS
Please see Email::Simple for the base set of methods. It won't take very long. Added to that, you have: create my $single = Email::MIME->create( header_str => [ ... ], body_str => '...', attributes => { ... }, ); my $multi = Email::MIME->create( header_str => [ ... ], parts => [ ... ], attributes => { ... }, ); This method creates a new MIME part. The "header_str" parameter is a list of headers pairs to include in the message. The value for each pair is expected to be a text string that will be MIME-encoded as needed. A similar "header" parameter can be provided in addition to or instead of "header_str". Its values will be used verbatim. "attributes" is a hash of MIME attributes to assign to the part, and may override portions of the header set in the "header" parameter. The "parts" parameter is a list reference containing "Email::MIME" objects. Elements of the "parts" list can also be a non-reference string of data. In that case, an "Email::MIME" object will be created for you. Simple checks will determine if the part is binary or not, and all parts created in this fashion are encoded with "base64", just in case. If "body" is given instead of "parts", it specifies the body to be used for a flat (subpart-less) MIME message. It is assumed to be a sequence of octets. If "body_str" is given instead of "body" or "parts", it is assumed to be a character string to be used as the body. If you provide a "body_str" parameter, you must provide "charset" and "encoding" attributes. Back to "attributes". The hash keys correspond directly to methods or modifying a message from "Email::MIME::Modifier". The allowed keys are: content_type, charset, name, format, boundary, encoding, disposition, and filename. They will be mapped to "$attr\_set" for message modification. content_type_set $email->content_type_set( 'text/html' ); Change the content type. All "Content-Type" header attributes will remain intact. charset_set name_set format_set boundary_set $email->charset_set( 'utf8' ); $email->name_set( 'some_filename.txt' ); $email->format_set( 'flowed' ); $email->boundary_set( undef ); # remove the boundary These four methods modify common "Content-Type" attributes. If set to "undef", the attribute is removed. All other "Content-Type" header information is preserved when modifying an attribute. encoding_set $email->encoding_set( 'base64' ); $email->encoding_set( 'quoted-printable' ); $email->encoding_set( '8bit' ); Convert the message body and alter the "Content-Transfer-Encoding" header using this method. Your message body, the output of the "body()" method, will remain the same. The raw body, output with the "body_raw()" method, will be changed to reflect the new encoding. body_set $email->body_set( $unencoded_body_string ); This method will encode the new body you send using the encoding specified in the "Content-Transfer-Encoding" header, then set the body to the new encoded body. This method overrides the default "body_set()" method. body_str_set $email->body_str_set($unicode_str); This method behaves like "body_set", but assumes that the given value is a Unicode string that should be encoded into the message's charset before being set. If the charset can't be determined, an exception is thrown. disposition_set $email->disposition_set( 'attachment' ); Alter the "Content-Disposition" of a message. All header attributes will remain intact. filename_set $email->filename_set( 'boo.pdf' ); Sets the filename attribute in the "Content-Disposition" header. All other header information is preserved when setting this attribute. parts_set $email->parts_set( @new_parts ); Replaces the parts for an object. Accepts a reference to a list of "Email::MIME" objects, representing the new parts. If this message was originally a single part, the "Content-Type" header will be changed to "multipart/mixed", and given a new boundary attribute. parts_add $email->parts_add( @more_parts ); Adds MIME parts onto the current MIME part. This is a simple extension of "parts_set" to make our lives easier. It accepts an array reference of additional parts. walk_parts $email->walk_parts(sub { my ($part) = @_; return if $part->subparts; # multipart if ( $part->content_type =~ m[text/html]i ) { my $body = $part->body; $body =~ s/<link [^>]+>//; # simple filter example $part->body_set( $body ); } }); Walks through all the MIME parts in a message and applies a callback to each. Accepts a code reference as its only argument. The code reference will be passed a single argument, the current MIME part within the top-level MIME object. All changes will be applied in place. header_str_set $email->header_str_set($header_name => @value_strings); This behaves like "header_set", but expects Unicode (character) strings as the values to set, rather than pre-encoded byte strings. It will encode them as MIME encoded-words if they contain any control or 8-bit characters. parts This returns a list of "Email::MIME" objects reflecting the parts of the message. If it's a single-part message, you get the original object back. In scalar context, this method returns the number of parts. subparts This returns a list of "Email::MIME" objects reflecting the parts of the message. If it's a single-part message, this method returns an empty list. In scalar context, this method returns the number of subparts. body This decodes and returns the body of the object as a byte string. For top-level objects in multi-part messages, this is highly likely to be something like "This is a multi-part message in MIME format." body_str This decodes both the Content-Transfer-Encoding layer of the body (like the "body" method) as well as the charset encoding of the body (unlike the "body" method), returning a Unicode string. If the charset is known, it is used. If there is no charset but the content type is either "text/plain" or "text/html", us-ascii is assumed. Otherwise, an exception is thrown. body_raw This returns the body of the object, but doesn't decode the transfer encoding. decode_hook This method is called before the Email::MIME::Encodings "decode" method, to decode the body of non-binary messages (or binary messages, if the "force_decode_hook" method returns true). By default, this method does nothing, but subclasses may define behavior. This method could be used to implement the decryption of content in secure email, for example. content_type This is a shortcut for access to the content type header. filename This provides the suggested filename for the attachment part. Normally it will return the filename from the headers, but if "filename" is passed a true parameter, it will generate an appropriate "stable" filename if one is not found in the MIME headers. invent_filename my $filename = Email::MIME->invent_filename($content_type); This routine is used by "filename" to generate filenames for attached files. It will attempt to choose a reasonable extension, falling back to dat. debug_structure my $description = $email->debug_structure; This method returns a string that describes the structure of the MIME entity. For example: + multipart/alternative; boundary="=_NextPart_2"; charset="BIG-5" + text/plain + text/html TODO
All of the Email::MIME-specific guts should move to a single entry on the object's guts. This will require changes to both Email::MIME and Email::MIME::Modifier, sadly. SEE ALSO
Email::Simple, Email::MIME::Modifier, Email::MIME::Creator. PERL EMAIL PROJECT
This module is maintained by the Perl Email Project <http://emailproject.perl.org/wiki/Email::MIME> AUTHOR
Casey West, "casey@geeknest.com" Simon Cozens, "simon@cpan.org" (retired) This software is copyright (c) 2004 by Simon Cozens. This is free software; you can redistribute it and/or modify it under the same terms as perl itself. THANKS
This module was generously sponsored by Best Practical (http://www.bestpractical.com/) and Pete Sergeant. perl v5.12.4 2011-09-12 Email::MIME(3pm)
All times are GMT -4. The time now is 04:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy