Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
60
rated 0 times [  60] [ 0]  / answers: 1 / hits: 81896  / 1 Year ago, wed, january 18, 2023, 12:18:55

I want to run my script in crontab, but I have some problems...



In my script I run this command:



db2 connect to myDB2


This works fine when I run this as db2inst1 user, but when I run this script in db2inst1 crontab, I get this:




db2: command not found.




How can I solve this?


More From » cron

 Answers
5

To avoid having to type the absolute path to a command, shells introduced the $PATH environment variable, each directory is separated by a : and searches are done from left to right. cron often clears the whole environment, including this $PATH variable. Therefore, the script may behave differently in your cron compared to the behavior in the shell.



Use absolute paths



Run which db2 as db2inst1 user to get the full path for the db2 program. If the output is /usr/bin/db2, your cron command would look like:



/usr/bin/db2 connect to myDB2


Set the PATH variable



Run echo "$PATH" as db2inst1 user to get the $PATH variable and make sure this variable is available in your cron script too. For example, if the output was /usr/local/bin:/usr/bin:/bin, you would put the next line in the top of your shell script:



export PATH="/usr/local/bin:/usr/bin:/bin"

[#44730] Wednesday, January 18, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
odyroc

Total Points: 324
Total Questions: 109
Total Answers: 103

Location: Belize
Member since Mon, Apr 17, 2023
1 Year ago
odyroc questions
;