Hi there, I use a CMS like application that use cron to send email notification every 30min, if the log contains something new. A bit naïevely, I followed the instalation tutorial of my app, ran "crontab -e", added a line like this "*/30 * * * * php /var/mydomain.com/web/check.php" At first I was happy as I could see that the cron job was indeed set-up, but not anymore for few reason : - if I run "crontab -e" again, I c'ant see/edit the cron job I created, it's like the line has diseappeared (for instance I would like it to run every 5minutes) --> I would assume that ISPConfig had re-edited this file to its liking and deleted my cron job, however - if I go to the log of my app, I still can see that my cron job is done every 30min I did some research and looked for my cron job in /etc/cron.d/ but couldn't find it. --> I thus wonder where could that job be specified now. Second, I then say to myself, stupid, why don't you use ISPConfig cron panel to create your cron job I thus created a cron job in ISPConfig, however if I specify an the url of check.php, the job will run "wget /var/mydomain.com/web/check.php" , and I obviously don't want that. Thus, in the same folder, I created a check.sh file containing "php /var/mydomain.com/web/check.php". If I run "sh /var/www/check.php" check.php is indeed run. I finally created a cronjob in ISPConfig with "/var/mydomain.com/web/check.sh" hopping it would be ran my script. But it's not. I did some research and tried "chmod -u+x /var/mydomain.com/web/check.sh" but it didn't help I double checked in "/etc/cron.d/ispc_chrooted_web1", where I can indeed see the cron job I created in ISPConfig. So my issue is double, what happened with my first cron job, has it been "managed" in a way by ISPConfig What have I done wrong in setting up a cron job in ISPConfig Thank's
1. Are you checking using crontab -l with the same user you created the crontab? 2. The crontab files are stored in /var/spool/cron/crontabs/ 3. You should never put check.sh in your web folder!!! 4. To check what ISPConfig generates as cron file look in /etc/cron.d/ispc_webxx, pay attention that this cron is run as the web user of the domain and not root
thank's dude ! I'm a dumb as* great thank's, i was looking into /etc/cron.d/* but I got fooled by ISPConfig I guess it's a security recommandation ? for now it's not an issue but I'll move ti to the private folder yes I've been there, and indeed see the cron job I created, but it do not seems to work. The owner/user of check.sh is the web user, as one could wish. In command line this user can run the script "sh /var/mydomain.com/web/check.sh" , but the job set in ISPConfig is not run... Do you get an idea what I may have done wrong ? Again the cron job created in ISPConfig contains the path to check.sh and check.sh contains "php /var/mydomain.com/web/check.php" Thank's
Did you check the log files to be sure that the cronjob is not run? Or maybe only the php execution fails, because the cronjob has no $PATH set... try to run php using the full path /usr/bin/php
Hi To my understanding, after some research, cron log is not activated by default. I thus edited /etc/rsyslog.conf and uncommented the line with cron.* /var/log/cron.log, then restarted cron and rsyslog service A fresh start being useful, I deleted the cron job I created manually, as well as the one in ISPConfig Then I created the cron job manually again, and it work's like a charm, it is recorded in both the cron.log file (much easier to read than rsyslog.log) and in my simili-cms log. I can now go further and delete this cron job (actually comment it) Then, logged-in as web5, I created a script, nano /var/www/mydomain.com/private/check.sh, containing /usr/bin/php /var/www/mydomain.com/web/check.php , finally made executable with chmod 755 /var/www/mydomain.com/private/check.sh If I run cd /var/www/mydomain.com/private/ then ./check.sh, check.sh is run, as well as check.php, as it is recorded in the log of my simili-cms Finally, I create a cron job in ISPConfig asked to run /var/www/mydomain.com/private/check.sh every 5 minutes. After a little while, the cron job appears to be run as it is recorded in /var/log/cron.log Sep 27 10:45:01 vpsXXXXXX CRON[1559]: (web5) CMD (/var/www/mydomain.com/private/check.sh >/dev/null 2>&1 #mydomain.com) However, if the cron job is run, check.sh do not seems to be run, and check.php is not, as I have no records in the log of my simili-cms. I don't know what have I done wrong ?! Thank's for your help
For debug purpose I would open the /etc/cron.d/ispc_webxx file and change MAILTO='' to MAILTO='[email protected]'. Then inside check.sh I would add some debug output like: echo 'debug' which php ls -la /usr/bin/php /usr/bin/php -v ls -la /var/www/mydomain.com/private/check.sh ls -la /var/www/mydomain.com/web/check.php and see if I get a mail with that contents to help me debug the issue. P.S.: Why can't you access check.php through wget? I am only using this type of cronjob for my clients and they work fine.
Ok I'll see what happens I may be even more dumb than one could guess. I assumes that if I were accessing check.php through wget, it would actually not run the script, but download it hat I usually use wget for in command line !!! Otherwise, I insist on doing it through ISPConfig, not only to have a "cleaner" set-up, which is not very true, but because it force me to dig into unknown area, and learn, in this case about cron, while I could have simply set-up the cron job as suggested in the documentation of the simili-cms without knowing much of what I'm doing, despite it works ;-)
Yes, but you do not need to call a shell script which calls php, just enter an URL into ISPConfig Command to run: http://mydomain.tld/check.php and your script will get called using the php version defined for that website...
yes I'm a dumb as** , it indeed works, I miss-interpreted what would wget do in the context of a cron job... Anyway, no I've been to far to quit, an I would like to have a cron job working with check.sh, just for the sake of learning, and acquire this ability I edited /etc/cron.d/ispc_webxx file and change MAILTO='' to MAILTO='[email protected]om'. and edited check.sh, it now contains excatly what you've written : Code: echo 'debug' which php ls -la /usr/bin/php /usr/bin/php -v ls -la /var/www/mydomain.com/private/check.sh ls -la /var/www/mydomain.com/web/check.php if I run ./check.sh I have Code: debug /usr/bin/php lrwxrwxrwx 1 root root 21 Sep 18 17:57 /usr/bin/php -> /etc/alternatives/php PHP 7.0.23-1+0~20170902060934.6+stretch~1.gbpa985da (cli) (built: Sep 2 2017 06:09:36) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.23-1+0~20170902060934.6+stretch~1.gbpa985da, Copyright (c) 1999-2017, by Zend Technologies -rwxr-xr-x 1 web5 client1 288 Sep 27 13:47 /var/www/mydomain.com/private/check.sh -rw-r--r-- 1 web5 client1 56 Sep 27 09:39 /var/www/mydomain.com/web/check.php the cron job seems done from the cron log Sep 27 13:35:01 vpsXXXXXX CRON[10131]: (web5) CMD (/var/www/mydomain.com/private/check.sh >/dev/null 2>&1 #mydomain.com) but no mail have been sent to [email protected], nor in spam :-(
OK, then try to remove (just for debugging) the ">/dev/null 2>&1" part in /etc/cron.d/ispc_webxx and hopefully you get a mail now.
Your problem is basically that you did not change the paths in your script match the chroot and that you call a program which you probably did not install inside the chroot. So what you posted as solution is basically no solution for others, you just posted how to disable cron security instead of fixing your custom shell script.
hi @till Thank's for your imput Now that I've read your answer, my question is diferent, altought maybe not super acurate ! how am I supose to change the path in my script to match the chroot ? how do I install a program inside a chroot ? The fact is I'm only creating a cron job to run a script which run a comand I'm asked to run by the creator of a web app
As it seems to be a custom program, install it in the same way you installed it there where you installed it now, just in the correct path of the chroot. For other applications, you can use jk_cp command.
yes yes, is it possible to merge this two post ? At first I thought I had a different problem but in the end it's exactly the same story ! Anyhow thank's a lot It was quite a fight to sort this out but I'm glad I did and I couldn't without this forum thank's again, and again, and again !