Jump to content

[SOLVED] PHP/Cron/Root issue?


matfish

Recommended Posts

Hi there,

 

I have a .php script which outputs some stats and emails them to me. I then have a .sh script that then curl's the php script on the webspace. And then a cron which invokes the .sh script.

 

If I log in via ssh as root and run the script or run the php script manually - all works fine. But if I let the cron invoke the script then I get the email but there are no stats attached?

 

If this an issue with cron or php?

 

Many thanks

Link to comment
Share on other sites

Hi there, forget about the above issue - It seems to be an issue on PHP script.

 

I do have another issue through and you kind of answered it above but still need a bit of guidence.

 

I use Plesk/RedHat5 and set up a crontab to run a .sh script on the server. I can see that ls -lut * in the shell's directory that the crontab is hitting the script at the correct time, but the .sh script is not doing anything. If I run the script as root in ssh it works fine.

 

You mentioned that cron is probably not running cron as root. Do I have to "chown user:user *" the files to something else as I'm not sure who it would be running as?

 

Many thanks

 

Link to comment
Share on other sites

Do I have to "chown user:user *" the files to something else as I'm not sure who it would be running as?

 

The script will be executing as the user whom setup the crontab. eg; If you log in as Jo and setup a crontab, the scripts within that crontab will be executed as though Jo was executing them. if you setup the scripts within roots crontab root will execute the scripts.

Link to comment
Share on other sites

Hi there,

 

I thought I understood the above but when I tried it still did not work.

 

I logged in via Plesk as "admin" chose the domain "123.com" hit "Crontab" and set up the crontab under the system user "123_user".

 

However the .sh script was created as "root" directly via SSH.

 

Any ideas from the above the chown permissions should be? I can still see that the script is being hit by cron, but nothing's happening.

 

Many thanks for your help

Link to comment
Share on other sites

Ive never used plesk (much rather using the shell itslef) but it would seem to me if your logging in as admin then your script will execute as the admin user. Does the script actually need to be run as root? And if so, why?

Link to comment
Share on other sites

I've tried chown admin:admin / admin:root / root:root / and still its hitting the .sh script but not actually running it. As a test the .sh script just "mkdir testdirectry" and... nothing!

 

It doesnt have to run as root or admin as long as it runs! When I logged into ssh using root it was fine. When I logged into ssh as admin there was a permissions error - but I fixed it and it runs from ssh as admin now - but nothing when using cron?

 

How do I find out what cron is running as?

 

Any other ideas? It's doing my head in!

 

Thanks for your help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.