0

I am writing an .sh file from where I am trying to access one .sql file where I have the query that needs to be run on scheduled basis.

Below is the line by which I try to make connection to the Database:

/home/mysql/mysql/bin/mysql --port=$PORT --host=$HOST --user=$DB_USER --password=$DB_PASSWORD --database=$DB_NAME < ${SQL_SCRIPT_PATH}${SQL_SCRIPT_NAME} >> ${LOG_FILE_PATH}${LOG_FILE_NAME}

But, the problem is when the scheduler is executed, it gives the below error:

[example@mchpXXX TEST_sh]$ sh updateMonthlyUserData.sh
updateMonthlyUserData.sh: line 15: mysql: command not found

Note: I tried to run this and got success if I run the sh file manually from putty and not through scheduler(crontab)

Kindly check and help.

Rohit
  • 188
  • 2
  • 18

1 Answers1

0

Crontab uses the default shell (sh) with minimal set of environment variables. most likely the PATH variable is not set properly.

I would set all the environment variables at the beginning of the script

#!/bin/bash
PATH=$PATH:/home/mysql/mysql/bin/:moreFolders

For further reading: How to get CRON to call in the correct PATHs https://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work

Community
  • 1
  • 1
asafm
  • 911
  • 6
  • 17