5

I have placed a .sh file that runs a php script weekly.

This script should run only once, but every sunday it runs at:

  • 1:30 am
  • 6:50 am

Any way to fix this?

OH CRAP

in the first email the user agent that request that email via web is: [HTTP_USER_AGENT] => Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.4.4

and guess who is the IP of the REQUEST ? it's the IP of my old server (where was setted the same cron job)

It's like the old server is requesting that cron via web, I just need to delete the cron job to my old server

dynamic
  • 730
  • 6
  • 17
  • 31
  • can you post the cron you have setup? – pablo Mar 06 '11 at 10:12
  • @pablo: done... – dynamic Mar 06 '11 at 10:37
  • 2
    In addition, please post the contents of /etc/crontab, which should define the schedule for run-parts. – beans Mar 06 '11 at 11:58
  • @beans: done.... (i never edit that file, it comes from debian 6) – dynamic Mar 06 '11 at 14:22
  • 3
    Well the 6:50 time is specified in the crontab file, so that one makes sense. The 1:30 time isn't. Is someone's personal crontab running the program in question (or executing some other part)? – Chris S Mar 06 '11 at 14:28
  • Can you list all users crontabs? – egorgry Mar 06 '11 at 14:45
  • @egrorgry: how? – dynamic Mar 06 '11 at 14:49
  • `crontab -l username`. If you have a lot of users this can be a pain but easily scripted if you need help with it comment back. – egorgry Mar 06 '11 at 14:52
  • @egro: i have 2 user: root and me :) – dynamic Mar 06 '11 at 15:12
  • @egro: anyway: `crontab -l`: no crontab for root, `crontab -u myuser -l`: no crontab for myuser. I don't think there are other users – dynamic Mar 06 '11 at 15:14
  • @yes123: what does the output of `sudo atq` have to say ? – user9517 Mar 06 '11 at 16:20
  • @lain: nothing. – dynamic Mar 06 '11 at 16:27
  • what evidence is there that the script is running twice? – JeffG Mar 06 '11 at 23:37
  • at the end of the script it sends me an email, every sunday i got 2 emails – dynamic Mar 06 '11 at 23:40
  • 2
    You might put a `ps -jHF` and `env` in your job to show the process tree and environtment for the job. That might help you find what's starting it. – beans Mar 07 '11 at 02:10
  • Check your cron logs (/var/cron/log or similar) to see what is causing this behaviour. – Shaun Dewberry Mar 07 '11 at 09:03
  • @shaun: Didn't find any cron logs, searched in `/var/cron/` and `/var/log/` – dynamic Mar 07 '11 at 11:48
  • @beans: in my job? Do you mean in my .sh file? After `#!/bin/bash` ? – dynamic Mar 08 '11 at 11:12
  • 2
    Yes. In the shell script. Anywhere after `#!/bin/bash` – beans Mar 08 '11 at 13:52
  • @beans: Considering is a cron if I put it there I don't think I can see the results.. (or it's automatically logged?) But anyway I think I can put it in my .php script (exec()) because as I said my .php script sends me an email with all the output.. should I do sudo too for running the commmand as root? (anyway +1 for the help) – dynamic Mar 08 '11 at 14:16
  • 1
    output from a cron job should be mailed to the user. Check your user's mail. It looks like your crontab is set up to run the weekly job as root. – beans Mar 08 '11 at 19:00
  • I don't think any emails is associated with the user/root. Anyway I have put those command in my php script with exec. Next time they will run i will recevie the output in my email – dynamic Mar 08 '11 at 19:41
  • @beans: after 1 week the emails have been both arrivide normally :D I updated the first post with the output of your command in email :) – dynamic Mar 13 '11 at 14:04
  • 1
    Is that the entire output of the ps command and the env command? Looks like you've truncated the output a bit. Is your 1:27 output really from apache? If so, I'd be looking at your apache access logs. Perhaps your mysterious cron job is executed from apache via a request from another machine. – beans Mar 14 '11 at 02:00
  • @bean: I edited the first post (separated the 2 cmd output). Anyway consider I took the output via my php script (saved the output of `exec("");`) I don't have apache access log, but I think I can save the $_SERVER['REQUEST_URI'] to check if the script is executed via HTTP or by CLI php (but sincerly i don't think someone run that script via HTTP) +1 for help anyway – dynamic Mar 14 '11 at 10:53
  • 1
    the `exec` php call stores multiline output in an array.. Looks like you are just printing the first record of that array, so your output is truncated. Try using print_r. One last thing, how is it possible that apache is not logging? Have you turned it off? – beans Mar 14 '11 at 12:49
  • @beans oh crap you right, i thought the return string of exec would have all the output.. Now we have to wait next week doh – dynamic Mar 14 '11 at 12:53
  • no you dont.. you can change the system's clock.. you can modify your cron job to execute in the next minute.. these might be helpful things to try anyway. – beans Mar 14 '11 at 14:24
  • can't change system time because some functions need it, anyway I think can move my shell script in the daily cron.. – dynamic Mar 14 '11 at 17:46
  • @beans: oh sh*t. The first email is executed from Apache2, the $_SERVER['REQUEST_URI'] is setted. O_O Please check the first post i updated it O_O – dynamic Mar 20 '11 at 09:15

2 Answers2

1

The job is being run by Apache at 1:27, not cron:

ps: www-data  9385  2405  2405  2405  0 47638 12984   1 Mar08 ?        00:00:00 /usr/sbin/apache2 -k start

env: APACHE_LOCK_DIR=/var/lock/apache2

Is httpd being restarted around that time? (Some startup code could be running this.) Alternately, does www-data have a crontab?

Paul Doom
  • 841
  • 6
  • 9
  • nope httpd isn't restarted. And how can I check www-data crontaqb? – dynamic Mar 14 '11 at 20:43
  • There would usually be a file named /var/spool/cron/crontabs/www-data, or just use the following to edit their crontab: sudo crontab -u www-data -e – Paul Doom Mar 15 '11 at 01:37
  • @paul: I added the full command output in first post. As you stated the cron of 1:27 is requested with the REQUEST_URI setted, like someone requested it via web (impossibile) How Can I solve this? [in crontabs there are 0 file] – dynamic Mar 20 '11 at 09:59
  • Check your HTTPD access.log and error.log for that time period. (Probably under /var/log/apache/) I don't think you have anything nefarious going on here, probably just some additional automation. For instance, a backup job could be calling it as a pre-backup task. – Paul Doom Mar 20 '11 at 17:54
  • I don't have any backup, this was a clean debian installation (from ovh) and i have installed only apache-php-mysql =/ – dynamic Mar 20 '11 at 18:23
  • Anything showing in the error.log or access.log? access.log should get you the IP of whatever is requesting the cronweek.php page – Paul Doom Mar 20 '11 at 18:27
  • finally thaanks to your suggest we got this. the ip requesting is the same ip of my old server (where was setted the same cronjob) he is requesting via web that page! FAIL xD – dynamic Mar 27 '11 at 17:23
0

I believe this will be relevant..

Under ubuntu or debian, you can view crontab by /var/spool/cron/crontab/ and then a file for each user is in there. That's only for user specific crontab's of course

By the way i got that from here....https://stackoverflow.com/questions/134906/how-do-i-list-all-cron-jobs-for-all-users