My BASH script work perfect when i run it manualy, but not when it run in the crontab
I am Cuban
Sorry by language bugs. I am run an script bash manually an d it run perfectly. I copy my script into the directory /etc/cron.daily and i programing the crontab to run everything into the cron.daily directory and the script run withow problems but the result it`s wrong. To be more especific: My script do a copy of a file; I run it manually and the file copied good with the same size. When the script run by crontab the file that i have copied has 0kb. Any subjection? |
The usual problem when scripts run at the command line but not from cron is that they rely on $PATH and cron sets a very basic $PATH.
Try setting $PATH in the script, for example Code:
export PATH='/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin' |
the solution don`t works any other subjection?
Help me please!!!
|
Your solution dont work my friend. do you have any other subjection.
|
set up your crontab so that the output of your script goes into some text file. for instance, my backup cron entry looks like this:
Code:
30 4 * * * php /var/www/cron/data_backup.php > /var/www/cron/data_backup.log like catkin said, the biggest difference between running a script via cron versus command-line is the path. another possible issue is permissions. when you run something from command line, it executes as whatever user you are logged in as. the cron job could be a different user depending on how you set it up. |
Make sure to use the whole path to all the commands and files in the script.
|
Assuming it's a bash script, try changing the first line to
Code:
#!/bin/bash -l sneakyimp's suggestion is good and may give useful information. Try it with 2>&1 at the end of the line, too. That may catch some error messages that > some_file alone does not. |
Dont work
Every that you tell me is already ok, and the problem continue.
Is someone have any other solution. I AM BECAME CRAZY!!! |
I found the problem
I found the possible problem:
I run a pg_dump on a PostgreSQL Data Base. In that line is the problem. I probed the line in a SHELL manually and work ok but not in the script. Any Subjections??? Please I need Help!!! |
Are you getting anything in the output file named after > in the crontab?
If so then you can add lines like Code:
echo "DEBUG $LINENO" |
Quote:
|
I'm wondering if he gets prompted for a password when running via CLI. the cron user may not have permission to dump the db.
|
This are the lines that are wrong
1- /usr/bin/pg_dump --host $hostName --port $port --username $userName --format tar --compress $compressLevel --file "/tmp/OBDBdump-$today-$now.db" openbravo
2- /usr/bin/pg_dump -i -h $hostName -p $port -U $userName -F c -b -v -f "/tmp/OBDBdump-$today-$now.db" openbravo both work ok manually, but not in the crontab help? |
Is anyone there?
Please Help Me!!! |
Did you try outputting the result of those lines to a file? If there are any errors, they would be written to the file so you could see the problem.
Also, you have not showed us your crontab. Is this crontab created for the same user that you login as when you run the commands from the command line? |
All times are GMT -5. The time now is 04:14 AM. |