Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
07-05-2017, 02:26 PM
|
#1
|
LQ Newbie
Registered: Jul 2017
Posts: 2
Rep:
|
Error executing shell script by crontab
Hi,
I have a shell script called runbackup.sh as follows:
Quote:
#!/bin/sh
cd ~frappe/frappe-bench/
pwd
bench backup
|
when I run this in command line, everything works fine. but when this executed by cron I am getting following output log:
Quote:
/home/frappe/frappe-bench
/home/frappe/runbackup.sh: 5: /home/frappe/runbackup.sh: bench: not found
|
Can anyone point out the issue, please.
BR/Mijan
|
|
|
07-05-2017, 02:31 PM
|
#2
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
Where is 'bench' located?
|
|
|
07-05-2017, 02:48 PM
|
#3
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,416
|
Quote:
Originally Posted by mijan1373
Hi,
I have a shell script called runbackup.sh as follows:
Code:
#!/bin/sh
cd ~frappe/frappe-bench/
pwd
bench backup
when I run this in command line, everything works fine. but when this executed by cron I am getting following output log:
Code:
/home/frappe/frappe-bench
/home/frappe/runbackup.sh: 5: /home/frappe/runbackup.sh: bench: not found
Can anyone point out the issue, please.
|
You posted it yourself...twice, actually. Think about how cron runs, and about the fact that you probably have put your cron job into the root cron, right?
Your first line is the "cd" command, with a relative path (the "~frappe/frappe-bench"). As root, you're trying to run "cd /root/frappe/frappe-bench"...which probably doesn't exist. So that's the first problem; don't use relative paths in scripts, but fully qualified paths.
Your second issue is that the "bench" command (the line 5 where you're getting the error), isn't in your PATH, and can't be found. Even *IF* the cd command worked...you're not specifying the directory to run it from. So unless you've got the "bench" command in your PATH, it'll die. Again, use fully-qualified paths. Why the "pwd" command as line 4?? Running that through cron will only output a current working directory, which does nothing. Your whole script could be just:
Code:
#!/bin/sh
/path/to/bench backup
or even better...don't have a script, just put the time into cron, and put "/path/to/bench backup" in. No need for a script.
|
|
|
07-05-2017, 03:03 PM
|
#4
|
LQ Newbie
Registered: Jul 2017
Posts: 2
Original Poster
Rep:
|
1. Please see the return of "pwd" command in the output, it is /home/frappe/frappe-bench where bench exists.
2. It is Ubuntu 14.04, there is no /home/root.
3. Crontab belongs to frappe user, not root.
That makes me confused.
BR/Mijan
Last edited by mijan1373; 07-05-2017 at 03:06 PM.
|
|
|
07-05-2017, 03:06 PM
|
#5
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,416
|
Quote:
Originally Posted by mijan1373
Please see the return of "pwd" command in the output, it is /home/frappe/frappe-bench where bench exists.
That makes me confused.d
|
It shouldn't, since when you're running that from your command-line prompt, that WILL be correct. When you run it through cron, it changes. Again, put a fully-qualified path in if you want this to work.
|
|
|
07-05-2017, 03:06 PM
|
#6
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
Yes. And if you just run
Then the shell will look for 'bench' in the PATH, not in the current directory. This is basic Linux shell info.
you would need
To fire it off from the local directory. Or even better yet, as Tb0ne says,. use the full path /home/whatever/whatever/bench
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 11:20 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|