LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 07-05-2017, 01:26 PM   #1
mijan1373
LQ Newbie
 
Registered: Jul 2017
Posts: 2

Rep: Reputation: Disabled
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
 
Old 07-05-2017, 01:31 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Where is 'bench' located?
 
Old 07-05-2017, 01:48 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by mijan1373 View Post
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.
 
Old 07-05-2017, 02:03 PM   #4
mijan1373
LQ Newbie
 
Registered: Jul 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
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 02:06 PM.
 
Old 07-05-2017, 02:06 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by mijan1373 View Post
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.
 
Old 07-05-2017, 02:06 PM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Yes. And if you just run

Code:
bench
Then the shell will look for 'bench' in the PATH, not in the current directory. This is basic Linux shell info.

you would need

Code:
./bench
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.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] crontab not executing the shell script. newhorizons009 Linux - Software 7 12-20-2016 11:31 AM
[SOLVED] Crontab not executing shell when date is added Jakkie Linux - Newbie 14 02-15-2012 05:18 AM
command not found error while executing a shell script SurbhiJain Linux - Newbie 15 07-26-2010 09:18 AM
Sntax error : unexpected end of file while executing shell script priyankarathi Linux - Newbie 5 04-21-2009 01:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration