Wednesday 20 June 2012

Linux Real Time Issues-1

-------------------------------------------
Q:Dear Friends,

I am running one application with Ubuntu 10.10. The application is working
fine.

Now I want to set a cron job in such a way so that it will fire a sql query
and create a .csv file and then it should send a mail to a particular
person with the attachment.

So for that I have set a cron job using command 'crontab -e' as below

0 21 * * * mysql -uroot -p'<pwd>' rnl_db -B -e "select * from \`Status\`;"
| sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n/ /g' > status_report.csv | mail -s
"Status Report" email@removed

It fires a sql command, it is creating a file but it doesn't send a mail.

Could anybody can help me to come out from this problem?
How can I send mail with attachment using cron?
Is there any other way?

Thanks & regards,

Ans:

1. Instead of using the mail command, try using mutt.

http://www.mutt.org/doc/man_page.html

something like this should work :
export EMAIL="Me email@removed" && mutt -s "subject" -a
/home/user/directory/file*.xls -- email@removed, email@removed <
/home/user/directory/message.txt

-a is the file to attach
-s is the subject
user1, user2 are the recipients
and message.txt is the body of the email

2. Hi,

" > status_report.csv | " is a part of your script

> means redirection and standard output of process will send to "status_report.csv"

Then pipe sign "|" means send standard output of process will be standard
input of next command.

">" and "|" together has no meaning you can use "tee" command.

Tee has one input and two outputs.


3. The shell is never getting to your mail command.
Once you used the > to redirect standard output
to the status_report.csv file there was no data to
feed to the pipe | so even if the mail command
could run, it would have had nothing to mail.
Here is one possible solution that may work for you:
1) Replace the pipe | with a semi-colon ;
this will cause the mail to run as a completely separate command
2) add <status.report.csv to end of the mail command
This will tell the mail command to mail out the file you just created.


4.
(1) Is it port 25 open

check

# netstat -ntpl | grep :25


(2) is iptable is active

iptables -L

if yes then

# iptables -f
# service iptables stop
#chkconfig iptbales off

(3) is selinux is working

to check

# getenforce
if 1

then

setenforce = 0 (TEMPERORY SOLUTION)

(4)

what is the size of csv file

send me the out put of /var/log/maillog

No comments:

Post a Comment