Setting up a crontab on debian/LINUX server - linux

I am trying to set up a crontab for a drupal 7 site. I installed elysia cron to schedule it and if I force it to run it runs fine. However I am having difficulty setting it up to call the cron.php file .
This is what I have on my crontab -e
*/5 * * * * /usr/bin/php "/var/www/test.ccc.com/cron.php"
And this is the error that I have been getting on my var/mail
PHP Warning: include_once(/home/neela/includes/bootstrap.inc): failed to open stream: No such file or directory in /var/www/test.ccc.com/cron.php on line 13
PHP Warning: include_once(): Failed opening '/home/neela/includes/bootstrap.inc' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/test.ccc.com/cron.php on line 13
PHP Fatal error: Call to undefined function drupal_bootstrap() in /var/www/test.ccc.com/cron.php on line 14
Also my test.ccc.com server is not live yet.
Any ideas?

Related

Cron Error :(cd) ERROR (getpwnam() failed - user unknown)

I have a simple bash script and it works fine when I execute it directly (bash testfile.sh). But when I use it in crontab, it is not working..
*/10 * * * * cd /var/trafficviewer/script; ./testfile.sh
I made the chmod +x testfile.sh as well.In error log, I could found below error..
Jul 12 16:45:01 XX crond[1439]: (cd) ERROR (getpwnam() failed - user unknown)
Can someone help me on this error?
Note: I dont have root access for this server. I installed these crons by using sudo commands.

Crontab not sending Sendgrid emails from Python script on AWS Linux 2

I have an AWS Amazon Linux 2 box. I am using a python script (Python 3.7) to send an email using Sendgrid as the SMTP service. I can send the email using $ python3 send_email.py but, when I use crontab ($ crontab -e then * * * * * python3 ~/apps/send_email.py), the error in the log file /var/log/cron is (CRON) EXEC FAILED (/usr/sbin/sendmail): No such file or directory. The crontab is working as expected (I've tested other cron commands and they work fine), but the email part is what's not working.
Here's what I've tried to fix it:
Run the command as a root crontab (ie $ sudo crontab -e)
Run the the crontab as a user crontab (ie $crontab -e)), but with sudo python3 ... in the crontab command.
Add the path directory at the top of the crontab file in case those directories couldn't be resolved
Installed Postfix to install something in the /usr/bin/sendmail directory but, since I don't need it to run the Sendgrid-powered email using $ python3 send_email.py, I'm not sure why I would need it through cron. I could be totally wrong on this, though. With Postfix installed, it resolves the (CRON) EXEC FAILED (/usr/sbin/sendmail): No such file or directory error in the cron log - the log entry in that case is (ec2-user) CMD (python3 ~/apps/send_email.py) - but I don't receive an email. Probably because Postfix isn't configured for the SMTP I'm using (Sendgrid).
(EDIT) I have configured Sendgrid to work with Postfix via the Sendgrid docs but it still won't send me an email although it looks like nothing is erroring out in the Postfix logs...
Jun 1 20:27:02 ip-[my-ip] postfix/pickup[25506]: 101769641F3: uid=1000 from=<ec2-user>
Jun 1 20:27:02 ip-[my-ip] postfix/cleanup[25508]: 101769641F3: message-id=<20210601202702.101769641F3#ip-[my-ip].us-east-2.compute.internal>
Jun 1 20:27:02 ip-[my-ip] postfix/qmgr[25507]: 101769641F3: from=<ec2-user#ip-[my-ip].us-east-2.compute.internal>, size=1165, nrcpt=1 (queue active)
Jun 1 20:27:02 ip-[my-ip] postfix/local[25510]: 101769641F3: to=<ec2-user#ip-[my-ip].us-east-2.compute.internal>, orig_to=<ec2-user>, relay=local, delay=0.01, delays=0/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Jun 1 20:27:02 ip-[my-ip] postfix/qmgr[25507]: 101769641F3: removed
My thought is that there is something in the cron call of the Sendgrid python lib (installed with sudo pip install sendgrid) that is failing out that doesn't happen when python calls it directly using the python3 interpreter from the CLI. I don't know why those would be different.
I was able to finally resolve this after much troubleshooting. Here's what worked.
I kept the original setup the same: Sendgrid for SMTP using their python lib (no Postfix or smtplib), using user crontab (using $ crontab -e not $ sudo crontab -e), and using Python 3.7.
Apparently the word 'email' in the python script name can cause interpreter issues so I renamed the file to remove the word 'email'. For example, send_noti.py instead of send_email.py
I used absolute paths for every call to a file in the python script. I was reading, writing, and executing files in the user directory in my python script as well as sending an email. Those R,W,X commands started erroring out in cron but not when called from outside of cron for some reason, even after renaming the file. Using absolute paths for all references to files fixed that.
I also used the absolute path for the python file in the crontab file. For example, * * * * * python3 /home/ec2-user/apps/send_noti.py instead of * * * * * python3 ~/apps/send_noti.py
I removed the unnecessary items in the crontab file I had put in before such as redefining the PATH directory.
I hope this helps someone because this took me about 3 weeks to troubleshoot and figure out.

ubuntu 18.04 is not accepting cron job

I am trying to set a cron job in ubuntu18.04 but it is giving me error of command not found
root#UB-Machine:~# * * * * * env > /tmp/env.output
Machine: command not found
I have tried restarting cron but still i am getting same error

How can I create folder and download remote images in that folder Using cron job

I am new to cron and I need all of your help , when I am using cron job to create folder and download images in that folder cron page giving me error that :
PHP Warning: imagejpeg(): Unable to open '././../uploads/lmf-classifieds-pk/folder2/2013-04-05/36258/1365138829_498747097_3-Khyber-1990-Urgent-sale-Islamabad.jpg' for writing: No such file or directory in /var/www/vhosts/ip-50-62-136-81.ip.secureserver.net/lmf_this/cron_lmf/function.php on line 143
PHP Notice: Undefined offset: 1 in /var/www/vhosts/ip-50-62-136-81.ip.secureserver.net/lmf_this/cron_lmf/olx_extract.php on line 562
PHP Warning: mkdir(): Permission denied in /var/www/vhosts/ip-50-62-136-81.ip.secureserver.net/lmf_this/cron_lmf/function.php on line 61
PHP Warning: mkdir(): Permission denied in /var/www/vhosts/ip-50-62-136-81.ip.secureserver.net/lmf_this/cron_lmf/function.php on line 65
PHP Warning: mkdir(): Permission denied in /var/www/vhosts/ip-50-62-136-81.ip.secureserver.net/lmf_this/cron_lmf/function.php on line 69
PHP Warning: mkdir(): No such file or directory in /var/www/vhosts/ip-50-62-136-81.ip.secureserver.net/lmf_this/cron_lmf/function.php on line 90
From these error .. I can understand cron job (page) is unable to create folder as well as download image .... Because of permission...
What should I need to do in this can ?
Please help me.
It looks like your script doesn't have the necessary permissions to do a mkdir on that folder,
check that you have write access.

Question about Pycron for windows

Hi I test my web on my localhost(winxp+ie8+mysql5.0.51a+PHP 5.2.11+Apache 2.2.13). I want to add some cron job for my php files. I select Pycron. After configuration, I add some command in crontab.txt * * * * * "C:\Program Files\Internet Explorer\IEXPLORE.EXE" http://localhost/test/index1.php. It is success, it will open IEXPLORE.EXE and load index1.php for every minute. But it still open the IEXPLORE windows, not for close. how to set it automatic finish the php job, then close the IEXPLORE windows? thanks.
how about using a command-line utility such as Curl or wget: http://gnuwin32.sourceforge.net/packages/wget.htm? Or use Python with urllib/urllib2?
To fire a local PHP event through Pycron, you'll want to do something like this:
First create a new task. Then for the "Command" box in Pycron, enter the location of your PHP.exe file, eg "C:\Program Files (x86)\PHP\v5.3\php.exe"
for the "Parameters" box enter the location of the php file you want to run eg "C:\websites\mysite.com\cron.php"
You don't want to run any of that through Internet Explorer. Fire it directly at the PHP executable. Your server will thank you.

Resources