LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-23-2009, 03:26 AM   #1
mackstar
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Rep: Reputation: 0
Bash script run via cron not executing MYSQL command


I have a bash script which is run from a cron,

It is executing as I have it write to a log file which it does correctly.

I am wanting the bash script to restore a mysqldump file.

When I run the bash script manually the dump file gets loaded fine. But when I run it through the cron the mysql command appears to be ignored.

The mysqldump file is 54MB and I have checked to make sure that MYSQL is included in the global users path in /etc/profile

Does anyone know why this maybe??

Here is the bash file
#!/bin/bash

date >> /home/user/crons/crons.log
echo "Started loadbackup" >> /home/user/crons/crons.log

cd /home/user

dbuser=root
dbpass=password
dbname=databasename
filename=backup

mysql -hlocalhost -u"$dbuser" -p"$dbpass" "$dbname" < "$filename".sql


date >> /home/user/crons/crons.log
echo "Finished loadbackup" >> /home/user/crons/crons.log
My crontab looks like

02 17 * * * /home/user/crons/loadbackup.sh

Many thanks

Richard

Last edited by mackstar; 04-23-2009 at 03:31 AM.
 
Old 04-23-2009, 03:30 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
try to use the whole path to all the commands you put in the script.
 
Old 04-23-2009, 03:42 AM   #3
mackstar
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 0
I think it has something to do with the "<" symbol as I try to add this to the log file and it gets cut off...

A possibility??

Many thanks

PS I tried the full path

when I enter "which mysql"

it gives me

/usr/local/mysql/bin/mysql

I used this and the script stopped working through the cron at all??
 
Old 04-23-2009, 03:48 AM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
try
Code:
whereis mysql
also add the whole path for all commands, eq date, echo.....
cron does not use the same PATH environment.

If the problem is ">" it wouldn't execute if you run it normally

Last edited by repo; 04-23-2009 at 03:54 AM.
 
Old 04-23-2009, 05:01 AM   #5
mackstar
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Actually date works fine...

I will try the whereis method instead though..

Thanks

Richard
 
  


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
Bash script can't handle errors when run by cron rosv Programming 4 01-08-2009 07:50 PM
Setting up cron to proccess a Bash Script to run every 15 minutes jamtech Programming 3 07-30-2007 03:32 PM
Run bash commands script as cron anjanesh Linux - General 4 04-03-2007 06:25 AM
How to run a bash command in the background from perl script professorfrink Programming 3 11-13-2003 03:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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