LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 09-21-2011, 05:12 PM   #1
theade
LQ Newbie
 
Registered: Sep 2011
Posts: 2

Rep: Reputation: Disabled
Unhappy Another "my cron is not working" thread...


Hello. Linux newb and first time poster, here. I'm sure it won't be the last

So, I've got a bitnami VM on AWS and I'm trying to get cron running a PHP script every minute. I've read through a gazillion other threads on this issue, but just can't fathom it.

So here's crontab -e:

* * * * * /tmp/test.sh
* * * * * date >> /tmp/cron_test.junk

note that I've now switched to a simple shell script rather than my original php script, to try to get it working (doesn't). The second like does actually work though. So...

test.sh just has:

echo `date` Success >> logs.txt

permissions:
ls -ll /tmp

-rw-r--r-- 1 bitnami bitnami 3248 2011-09-21 21:07 cron_test.junk
-rwxrwxrwx 1 root bitnami 74 2011-09-21 18:46 logs.txt
-rwxrwxrwx 1 root bitnami 32 2011-09-21 18:43 test.sh

As I said, the cron is def running cos cron_test.junk is getting updated.

I must be doing something ridiculous, what on earth is it?

Thank you!!

Theade
 
Old 09-21-2011, 05:56 PM   #2
BertM
LQ Newbie
 
Registered: Jan 2010
Location: Belgium
Distribution: Debian
Posts: 17

Rep: Reputation: 0
Try adding "/bin/bash" in your crontab:

* * * * * /bin/bash /tmp/test.sh

Or replace it with your shell if you use another one.
 
Old 09-21-2011, 06:00 PM   #3
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Are you missing a hash-bang?

Try changing test.sh to:

Code:
#!/bin/sh

echo `date` Success >> logs.txt
 
Old 09-21-2011, 06:11 PM   #4
theade
LQ Newbie
 
Registered: Sep 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Cheers for suggestion both, but nnnnope, no joy.

I also don't have a cron log file in /var/log/cron which a lot of other threads have said to check...

Mmmmm...
 
Old 09-21-2011, 06:29 PM   #5
BertM
LQ Newbie
 
Registered: Jan 2010
Location: Belgium
Distribution: Debian
Posts: 17

Rep: Reputation: 0
Did you check your mail? When one of my cronjobs fails, I automatically get sent one.

Just type mail in a terminal and if there are new mails, type the number and press the Return key.
 
Old 09-21-2011, 06:29 PM   #6
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 518

Rep: Reputation: 177Reputation: 177
From man 5 crontab on my Debian box:
Quote:
Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive.
Try:

0-59 * * * * /tmp/test.sh

Edit: Ignore below, misread your post #4

From man 1 crontab:
Quote:
Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs,

Last edited by norobro; 09-21-2011 at 07:40 PM.
 
Old 09-21-2011, 06:42 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Definitely check mail using eg mailx, both as root and as the job owner.
Also, I'd be inclined to always specify full absolute paths to all cmds/files referenced eg that logs.txt file.
Easiest way is to just explicitly call a shell file in cron, then (after the shebang line eg '#!/bin/bash'', in the next line) set PATH explicitly as reqd for your prog eg copy the content of your .bash_profile.

a basic way to debug bash is to use
Code:
set -xv
after the shebang line; it shows what the parser is doing.
In cron you'll prob get the output emailed, although you can also do

Code:
* * * * * /dir/t.sh >/tmp/t.log 2>&1
PS always use 'crontbab -e' to edit your cron file. If you edit it directly cron daemon may not be notified of the change.

Last edited by chrism01; 09-21-2011 at 06:43 PM.
 
1 members found this post helpful.
Old 09-22-2011, 04:31 AM   #8
resolv_25
Member
 
Registered: Aug 2011
Location: Croatia
Distribution: Debian 7/Ubuntu 14.04
Posts: 57

Rep: Reputation: 9
I had problems with PHP script from a cron.

This shall work:
- Install lynx, text based web browser and put this in cron:

Code:
* * * * * lynx -dump http://www.myhost.com/cron.php
(if local server: http://localhost/cron.php)


- The other way:
leave cron as it is, but put this first line at a beginning of a PHP:

PHP Code:
<?php
#!/usr/local/bin/php -q
     
echo "Your script";
?>
Also, it depends if your web server is setup as CGI ?
If CGI, second option will work out.

Last edited by resolv_25; 09-22-2011 at 06:05 AM.
 
Old 09-22-2011, 04:38 AM   #9
resolv_25
Member
 
Registered: Aug 2011
Location: Croatia
Distribution: Debian 7/Ubuntu 14.04
Posts: 57

Rep: Reputation: 9
If you prefer to call a bash script from cron, you may use the same approach:

Code:
#!/bin/sh
lynx -dump http://myhost/cron.php
# (if CGI): php /full/path/cron.php
(also, in the case that you will run several separated php scripts)
 
Old 09-29-2011, 03:40 AM   #10
zaid1kd
LQ Newbie
 
Registered: Sep 2011
Posts: 1

Rep: Reputation: Disabled
I want to download cron pdf for learning can anyone provide me the link to download it.
 
Old 09-29-2011, 03:55 AM   #11
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Quote:
Originally Posted by zaid1kd View Post
I want to download cron pdf for learning can anyone provide me the link to download it.
Hello,

Please do not thread jack other people's threads. If you have a serious question, search these forums first, and if you can not find the answer you are looking for, then by all means create a new thread. Now as far as your "question," try search online, specifically on google, for "cron guide" and you will find quite a few results.

Cheers,

Josh
 
Old 09-29-2011, 04:00 AM   #12
snooly
Member
 
Registered: Sep 2011
Posts: 124

Rep: Reputation: Disabled
Quote:
Originally Posted by theade View Post
permissions:
ls -ll /tmp

-rw-r--r-- 1 bitnami bitnami 3248 2011-09-21 21:07 cron_test.junk
-rwxrwxrwx 1 root bitnami 74 2011-09-21 18:46 logs.txt
-rwxrwxrwx 1 root bitnami 32 2011-09-21 18:43 test.sh
You shouldn't be setting your permissions like that, you'll get pwned. You've set the script that you're running from cron to be world-writable, and put it in the tmp directory. If anybody gets access to your machine, they can change that script to whatever they want, and if they are malicious, you can wave bye-bye to your machine and your precious data. You should never set any executable to be world-writable. There is no need for it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
script using "/usr/bin/cat error" produces "cannot open" in cron Dcrusoe Programming 6 07-22-2009 04:30 PM
net working eth0 eth1 wlan0 "no connection" "no LAN" "no wi-fi" Cayitano Linux - Newbie 5 12-09-2007 08:11 PM
"NIM thread blocked" & "Deadman Switch (DMS) close to trigger" errors sosborne Linux - Networking 1 06-28-2006 03:07 PM
"NIM thread blocked" & "Deadman Switch" errors sosborne AIX 3 06-01-2006 12:21 PM


All times are GMT -5. The time now is 10:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration