LinuxQuestions.org
Help answer threads with 0 replies.
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 06-04-2021, 06:24 AM   #1
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Rep: Reputation: 0
Sending sql query result by mail


Dear all,
i can make a sql connection to db with sqlplus
and after i connect, i write a query. i want to make a script to get this query result in every 2 hour.

how can i do that?

thank you.
 
Old 06-04-2021, 07:26 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,623

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
One (my) solution:

Wrap your query in a shell script, pipe your query output to a file, have your script fire up an email client to send and email as you require with that file attached.

If the output is small, you can html wrap it and make it part of the body of the email. How useful this is might depend partly upon what email client you READ it in, so testing your solution should include reading tests with any different clients you might use.

Last edited by wpeckham; 06-04-2021 at 07:38 AM.
 
Old 06-04-2021, 07:31 AM   #3
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by wpeckham View Post
Wrap your query in a shell script, pipe your query output to a file, have your script fire up an email client to send and email as you require with that file attached.

If the output is small, you can html wrap it and make it part of the body of the email. How useful this is might depend partly upon what email client you READ it in, so testing your solution should include reading tests with any different clients you might use.
hi there, thank you for the answer.

i only want to connect sql by sqlplus ***/***@10.200.200.200:1561/ser

and then i want to run this command : select * from SESSION;

and i only want to send the output of this query result by mail. thats all i want.
 
Old 06-04-2021, 07:47 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546

Ok, so what exactly have you tried, and where in the process are you stuck?

Have you read any of the sqlplus user guide or performed any searches?

https://www.linuxquestions.org/questions/faq.php?faq=welcome

 
Old 06-04-2021, 07:53 AM   #5
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by boughtonp View Post
Ok, so what exactly have you tried, and where in the process are you stuck?

Have you read any of the sqlplus user guide or performed any searches?

https://www.linuxquestions.org/questions/faq.php?faq=welcome

it worked, i got the result as an output. only i want this output to send me by mail every 2 hour. only i couldnt do that.
 
Old 06-04-2021, 08:01 AM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546
Quote:
Originally Posted by TravisBrooker View Post
it worked, i got the result as an output. only i want this output to send me by mail every 2 hour. only i couldnt do that.
Then consult your previous threads where you have examples of both sending emails and using cron!


You should also read and understand all of the following, but especially the emphasized parts:
Quote:
Originally Posted by https://www.linuxquestions.org/questions/faq.php?faq=welcome
Hello and welcome to LQ. You were pointed here because a fellow LQ member feels the thread you started doesn't meet the minimum threshold that would enable us to help you. We understand that Linux can be intimidating for new members, and we really do want to help. That said, please understand that LQ is not a help desk, customer service line for a product you purchased or willing to do your homework (although we are happy to assist you with specifics, if you show some effort of your own!). We're a 100% volunteer organization that wants to help you help yourself.

Here are a couple tips that will enable us to help you moving forward:

When asking a question, be sure to provide as many relevant details as possible. You should include the distribution and version you're using, along with hardware details, application version and exact error messages where applicable.
Using a descriptive title will vastly increase the number of members who see your thread, and therefore make a response significantly more likely.
If you're actively troubleshooting an issue you should also include any steps you've already taken.
You may want to include how what you are experiencing differs from what you expected to experience.

Before posting, have you used the search function to ensure your question hasn't been asked before?
You can edit your post by clicking the EDIT button in the bottom right corner of your message.

If you are unwilling or unable to ask questions in a manner that allows us to help you, it's unlikely our community will be able to provide you a solution. Unfortunately, serial offenders who show wanton disregard for this request after multiple pointers may be asked to seek help elsewhere. We truly hope that isn't necessary, and assure you Linux and Open Source are extremely rewarding and well worth the learning curve in the long run.

Last edited by boughtonp; 06-04-2021 at 08:03 AM.
 
Old 06-04-2021, 08:49 AM   #7
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
Here is a function I use to send emails to myself from my server. Should get you started. Uses msmtp.

Code:
emergency_email_func() {
	EMAILLOC=/tmp/"$(uname -n)"."$2"."$NOW".alert
	echo "To: ${1}
From: $(grep from "$HOME"/.msmtprc | cut -d' ' -f 2)
Subject: $(uname -n) alert!

" > "$EMAILLOC"
	echo "snapraid scrub finished with errors. check manually" >> "$EMAILLOC"
	msmtp "$1" < "$EMAILLOC"
	rm "$EMAILLOC"
}
 
Old 06-09-2021, 12:54 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Here's a basic one-liner you can expand on
Code:
(shell script)| mailx -s "Email subject" <your email addr>
Basically, this runs your code in a sub-shell, whose o/p is captured and sent as the body of an email with subject you specify in quotes, then your email.
 
  


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
result of : top -o COMMAND ? explain the result please mike1047 Linux - Newbie 2 10-31-2019 09:20 AM
result of : top -o COMMAND ? explain the result please mike1047 Linux - Newbie 3 10-31-2019 09:18 AM
am not getting any result when am using 'if', without getting result for below script alavala53 Linux - General 3 10-25-2012 06:00 PM
[SOLVED] Grep for the result of a command within the result of another command jasonws Programming 6 11-18-2010 02:39 PM

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

All times are GMT -5. The time now is 11:48 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