LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-29-2011, 04:13 PM   #1
ice2921
Member
 
Registered: Jan 2008
Posts: 74

Rep: Reputation: 15
Cron Jobs not working


Hello,

I have a script that works manually, but not when setup in crontab. Any ideas? let me know if you need more info thanks.
 
Old 12-29-2011, 04:14 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Since cron has a limited path, try to use the whole path to the commands and files in the script.

Kind regards
 
Old 12-29-2011, 04:20 PM   #3
ice2921
Member
 
Registered: Jan 2008
Posts: 74

Original Poster
Rep: Reputation: 15
This is my cron entry:

Code:
2 1 * * * root /usr/local/bin/myscript.sh > /var/log/myscript.log 2>&1
Its the direct path to the script.
 
Old 12-29-2011, 04:22 PM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
Its the direct path to the script.
Use the absolute path to commands and files in the script itself.

Kind regards
 
Old 12-29-2011, 04:24 PM   #5
ice2921
Member
 
Registered: Jan 2008
Posts: 74

Original Poster
Rep: Reputation: 15
Im sorry im still a bit green. What would an example be? thanks
 
Old 12-29-2011, 04:33 PM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Edit myscript.sh
If you have a command, lets say
Code:
ls /home
use
[CODE]/bin/ls /home
Or set the path at the beginning of the script
Code:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Kind regards

Last edited by repo; 12-29-2011 at 04:36 PM.
 
Old 12-29-2011, 04:36 PM   #7
ice2921
Member
 
Registered: Jan 2008
Posts: 74

Original Poster
Rep: Reputation: 15
Ok so I execute
Code:
[root@myserver-1 bin]# whereis myscript.sh
myscript: /usr/local/bin/myscript.sh
So wouldn't /usr/local/bin/myscript.sh be the absolute path?
 
Old 12-29-2011, 04:38 PM   #8
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
So wouldn't /usr/local/bin/myscript.sh be the absolute path?
You need to set the absolute path from the commands and files IN the script

Kind regards
 
Old 12-29-2011, 04:51 PM   #9
ice2921
Member
 
Registered: Jan 2008
Posts: 74

Original Poster
Rep: Reputation: 15
still not working. It has to be something simple, it seems like everything is telling me that usr/local/bin/myscript.sh is the absolute path. Im not sure how to get to the command absolute paths.

Last edited by ice2921; 12-29-2011 at 04:53 PM.
 
Old 12-29-2011, 04:56 PM   #10
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Add this at the top of the script
Code:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Or post the contents of your script

Kind regards
 
Old 12-29-2011, 05:08 PM   #11
ice2921
Member
 
Registered: Jan 2008
Posts: 74

Original Poster
Rep: Reputation: 15
Here is one that I am testing:

Code:
#!/bin/bash
echo Hello World
 
Old 12-29-2011, 05:13 PM   #12
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Try
Code:
#!/bin/bash
/bin/echo Hello World > /var/log/myscript.log
Then look in
Code:
/var/log/myscript.log
Kind regards
 
Old 12-29-2011, 05:17 PM   #13
ice2921
Member
 
Registered: Jan 2008
Posts: 74

Original Poster
Rep: Reputation: 15
It works I get:

Code:
[root@myserver-1 bin]# cat /var/log/myscript.log
Hello World
[root@myserver-1 bin]#
 
Old 12-29-2011, 05:27 PM   #14
ice2921
Member
 
Registered: Jan 2008
Posts: 74

Original Poster
Rep: Reputation: 15
I added that to cron and its still not working.
 
Old 12-29-2011, 05:29 PM   #15
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
I added that to cron and its still not working.
You added what to what?
Try
Code:
2 1 * * * /usr/local/bin/myscript.sh
no need for root
If there are any problems, cron will sent a mail to root.

Kind regards
 
  


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
cron hourly, daily, cron.d jobs don't execute eggsmartha Linux - General 3 09-17-2007 06:37 PM
FC6 cron not working - won't run any jobs joshv Fedora 1 04-29-2007 06:20 PM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
Cron Jobs XaViaR Linux - General 1 06-23-2005 06:57 PM
cron jobs Zyanid Linux - Software 0 08-27-2002 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:39 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