Solved

MySQL from crontab

Posted on 2011-09-11
2
578 Views
Last Modified: 2013-11-22
I created a file named "dbrun.sh":
mysql -u zooph -ppass123 -h m.example.com zooph_db < /usr/home/zooph/cron/cron.sql > /dev/null
touch /usr/home/zooph/cron/cron.txt

Open in new window


When I run the file like this the MySQL queries in the MySQL get exicuted:
sh dbrun.sh

Open in new window

However when the crontab does NOT run the SQL dump:
*/1 * * * * sh /usr/home/zooph/cron/dbrun.sh

Open in new window

The "touch" command works but not the MySQL dump.
0
Comment
Question by:hankknight
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 36519200
possibly because the mysql is not in the path?
try to modify dbrun.sh so that you specify the full path name ...
0
 
LVL 77

Assisted Solution

by:arnold
arnold earned 100 total points
ID: 36519279
If you want something to run every minute, just use * versus */1
But as angelIII pointed out the location of mysql might not be in the path and
/bin/sh instead of sh or add to the top of your script:
#!/bin/sh
and change mode of the file to 755.

/usr/bin/mysql
/usr/local/bin/mysql should be used instead of the mysql you have.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
category table 2 25
Insert values are dynamic 11 41
open source backup solution 1 29
BACKUP of mysql database from mysql server - using Coldfusion 9 37
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question