LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 01-09-2014, 10:44 PM   #1
alec1024
LQ Newbie
 
Registered: Jan 2014
Posts: 1

Rep: Reputation: Disabled
Cron syntax


Hi all,

Please help with syntax, i'm trying to send results of mysql query to my email....and it works if i'm starting it manualy :
mysql -uroot -pqwerty otrs -H < /home/send_otrs2.sql | mail -a "Content-type: text/html;" -s "SLA Report for $(date --date '1 month ago' +%B)" alec1024@gmail.com >> /dev/null

but if i'm trying to do this in cron:
# SLA report
* * * * * mysql -uroot -pqwerty otrs -H < /home/send_otrs2.sql | mail -a "Content-type: text/html;" -s "SLA Report for $(date --date '1 month ago' +%B)" alec1024@gmail.com >> /dev/null
I'm receving this error - /bin/sh: 1: Syntax error: end of file unexpected (expecting ")")

Problem is in "+%B" , without this month name everything works fine. IS there some specific syntax in cron ?
 
Old 01-09-2014, 11:42 PM   #2
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,204

Rep: Reputation: 197Reputation: 197
not tested but you can try, just add some character before %B

Quote:
mysql -uroot -pqwerty otrs -H < /home/send_otrs2.sql | mail -a "Content-type: text/html;" -s "SLA Report for $(date --date '1 month ago' +=%B)" alec1024@gmail.com >> /dev/null

Last edited by JJJCR; 01-09-2014 at 11:44 PM. Reason: edit
 
Old 01-10-2014, 03:16 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
@alec1024: The % is a special character (seen from cron), it needs to be escaped.

Have a look at this related LQ thread: One issue with Crontab

BTW: It would be better to put the complete statement into a small script an run that from cron.
 
1 members found this post helpful.
Old 01-10-2014, 07:59 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,687

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
It would be easier to put the command in a script file and then invoke the script from cron.

It also makes it easier to update and much less prone to errors.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Error running cron job, syntax error? mpyusko Debian 2 12-20-2012 09:57 AM
Syntax for : Receiving email once Cron job is completed Linux_Newbee83 Linux - Newbie 5 01-04-2012 09:11 PM
mysqldump syntax for cron irvken Linux - General 3 03-07-2010 12:37 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
Cron Job Syntax for a task in seconds AJones Linux - Software 2 07-22-2005 12:56 PM


All times are GMT -5. The time now is 12:58 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration