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.
if ($flag = true); then echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- The OpenBravo BK has finished OK ----------">> $openbravoLogFile;
echo 'Salva de OpenBravo-Satisfactoria.' > $email;
python /tmp/sendMail.py; else
echo "$(date +%Y) $(date +%B) $(date +%d) $(date +%A) $(date +%T) ---------- The OpenBravo BK has not finished ----------">> $openbravoLogFile; fi
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.
That's tidier MTK358 but does it make any functional difference?
I doubt it.
It's just that this "2>&1" thing really irritates me because it's placement just doesn't go with the flow of data. Also I don't understand it's syntax.
What do these do?? I know you can use ampersand to background some stuff, but haven't seen a > arg1 arg2 before, much less a command > arg1 arg2>arg3
The tokens you represent as arg1-3 are not arguments; arg1 is an redirection target, arg2 is a file descriptor (in this case fd 2 which is stderr) and arg3 means "the same place as fd 1 is going to". Redirections are explained here.
Am I the only one in the universe that knows about bash's &> operator and have to explain it to everyone?
It redirects both stdout and stderr to a file.
Also, "2>&1" never really made sense to me. I just know that "&>" is an elegant replacement that actually makes logical sense.
I guess many of us have old habits, from before &> was available. Personally I don't find the usage of & in &> any more logical or intuitive than its usage in 2>&1!
Hey gays It WORK!!!
Thank you very much
The 2>&1 in the end of the command line written in the script WORKKK!!!
Now thank to you my script work ok!!!
If anyone of you need something don't dude
Call me
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.