I have the following file named crons.txt
In this file I have:
*/2 * * * * wget -q -O - http://www.mydomain.com/testcron.php
^ Should run every 2 minutes...
Now I go into SSH and enter the following command:
crontab /home/crons/game.txt
Which returns
"/home/crons/game.txt":0: bad minute
errors in crontab file, can't install.
I'm not sure what im doing wrong, the command looks ok to me... Does anyone know what i'm doing wrong?
Related
I setup several cron jobs to make things work. laravel scheduler works perfectly but my other cronjobs not working at all.
*/2 * * * * /usr/bin/php /var/www/cronjobs/index.php
when I run on the console /usr/bin/php /var/www/cronjobs/index.php it works properly. I checked executable php path with which php and gives me /usr/bin/php nothing wrong with path afaik. I tried to run php script as apache user www-data I opened crontab with crontab -u www-data -e and paste command there.. it didn't work too.
I also tried send dummy notify with crontab and it also didn't work either
dummy example
* * * * * /usr/bin/notify-send 'test'
both of them doesn't work. What am I missing here ?
The second command will not send notification as cron have no idea of your desktop environment.
The first command probably use some environment variables. So instead of run in command line you can try to create a script:
#!/bin/bash
source /path/to/user/home/.bashrc #you can try also .bash_profile
/usr/bin/php /var/www/cronjobs/index.php
and your cron to be like:
*/2 * * * * /path/to/script.sh
I have set some commands in my crontab, but it seems like they are not executed.
PHP version is 7+
CentOS 7
This is my list when I run "crontab -u username -l"
45 0 * * * username /usr/bin/php /var/www/production/site/scripts/process1.php
*/2 * * * * username /usr/bin/php /var/www/production/site/scripts/process2.php
25 * * * * username /usr/bin/php /var/www/production/api/scripts/process3.php
username is an existing user and has rights to the PHP files. Same results when I use the root user.
When I run "Which php" I get the result below:
/usr/bin/php
So that seems to be OK too.
/var/log/cron shows me lines like this, so it appears to be called
CROND[29053]: (username) CMD (username /usr/bin/php /var/www/production/site/scripts/process1.php)
When I run the commands manually all works well, so the processx.php files seem to be OK.
I am running out of ideas... Can anybody point me to the right direction to tackle my (probably silly) mistake?
Alright, it is working... Still not 100% sure why it was not before.
But this is what I changed:
removed the processes with the command "crontab -e" and deleted the 3 commands there.
Then:
nano /etc/crontab
Added the commands there (with the right user to execute them) e voila!
Difference was that I used /etc/crontab directly and not using crontab -e.
Although I am now still curious why this is working and my first attempt through crontab -e is not... So, if anybody knows why, please let me know!
I'm having a PHP script which I want to run every 2 minutes using a Cron job in Ubuntu. I'm getting the following error:
bash: */2: No such file or directory
I've completed all steps below to set up a Cron job.
Please help me to resolve the error, I don't understand what I'm doing wrong.
1) Write this command in my terminal: where is php
Output:
php: /usr/bin/php /usr/bin/X11/php /usr/share/php /opt/lampp/bin/php /usr/share/man/man1/php.1.gz
2) Run a PHP script every 2 minutes:
*/2 * * * * /usr/bin/php /opt/lampp/htdocs/kyrill/filetest.php
Output:
bash: */2: No such file or directory
Seems like you are executing the crontab directive.
Execute
crontab -e
to edit your cron jobs. Then add this line at end of the file
*/2 * * * * /usr/bin/php /opt/lampp/htdocs/kyrill/filetest.php
try
0/2 * * * * curl http://[your_id:port]/kyrill/filetest.php
I am trying to run an automated tasks from php script which I couldn't run. For testing purpose, I created test.php and still nothing is working.
These are the lines I executed in the flow
crontab -e
This opened nano with
#.............hint text were here
#.............hint text were here
* * * * * /usr/local/bin/php -f test.php
then I restarted the crontab
sudo service cron restart
confirmed the cron is working using
pgrep cron
and got the result. Also
/usr/local/bin/php test.php
also gave me Hello World in the terminal
Test.php
!#/usr/local/bin/php
<?php
echo "Hello World";
?>
The cronjob is also confirmed by executing
crontab -l
Tried to set permissions too
chmod +x test.php
chmod 755 test.php
chmod 600 test.php
Looking for a support to make it happen. Thanks.
Chances are your crontab is working but you just don't see the output because by default cron mails the standard and error output to the owner of the cron job. So what you can do is redirect them to a file and check it out manually.
You can do that by editing the crontab entry so that it looks like this:
* * * * * /usr/local/bin/php -f test.php > /tmp/log.log 2>&1
And then in a minute you can check it out to make sure your job is actually working.
I hope this helps.
EDIT
As it turned out in the comments of the question there was actually an error /bin/sh: 1: usr/local/bin/php: not found recorded in the log.log file which was fixed by just using php
Try doing the following
*/1 * * * * [username] /usr/local/bin/php -f test.php
e.g. */1 * * * * root /usr/local/bin/php -f test.php
I am problem scheduling and running a script through cron job. I am on linux (ubuntu), it is a VPS.
What I am doing is I have put this line in crontab file that is here: /etc/crontab
I wrote:
*/15 * * * * www-data php /var/www/abs/phpscript.php
I have given 777 to the file and after writing above in crontab , I run command:
crontab crontab
Then after almost some time I got the mail in my /var/mail/username file that says: /bin/sh: root: not found
So I am unable to understand what is the problem.
I also run phpinfo and it shows the third variable as APACHE that probably means that PHP is running as apache module.
Please tell what can be the possible solution.
thanks in advance to every one who will try to solve my problem.
You can try also to run it using "wget -q -O"
or
*/15 * * * * lynx -dump "url" > /dev/null
Wget examples:
*/15 * * * * wget -O /dev/null 'http://www.mydomain.com/document.php?&user=myuser&password=mypass' >/dev/null
If you need to post data you can use
--post-data "login=user&password=pass"
*/15 * * * * wget -O /dev/null 'http://www.mydomain.com/document.php?&user=myuser&password=mypass' --post-data 'foo=bar' >/dev/null
If you edited /etc/crontab, you should re-read the warning at the top of the file:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
Running crontab(1) on the /etc/crontab file probably contaminated the root user's crontab(5) file (the one stored in /var/spool/cron/crontabs/). I suggest running crontab -e as root to edit the crontab file, and remove all the entries that are identical to the entries from /etc/crontab. (Maybe you just contaminated your own personal crontab(5) -- if crontab -e as root didn't show anything, run crontab -e under your own personal account and see if the system-wide entries were duplicated into your own crontab(5).)
I don't know what file you ran chmod 777 on, but that was probably unnecessary. You really should set your permissions to be as strict as possible to confine the results of malicious attacks or unintentional mistakes.
You are running a crontab as a user, which means you can't specify the user in the cron.
The template you borrowed your example from was for a system (root) cron.
Remove the username and try again.