My BASH script work perfect when i run it manualy, but not when it run in the crontab
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
if the cron job fails, i can check the contents of /var/www/cron/data_backup.log to find any error messages which may have been generated.
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.
Assuming it's a bash script, try changing the first line to
Code:
#!/bin/bash -l
That's a letter l for login. It will make bash simulate logon so you get your usual environment, similar to at the command line.
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.
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!!!
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.
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.