I have .sh file on redhat to run a crontab.
Content of this file
#!/bin/bash
echo "run every 1min..."
I run it with the command:
[root#localhost ~]# * * * * * /var/www/html/ac/bc/1.sh
bash: anaconda-ks.cfg: command not found
The cron configuration rule is not a shell command (although it ends with one).
You have to enter it into your cron configuration, not enter it at the command prompt.
Run crontab -e to edit your cron configuration.
type
crontab -e
press i
paste the line
* * * * * /var/www/html/ac/bc/1.sh
next save crontab
press
esc
type
:wq!
Type crontab -e then type your cron command.
Then to save it press ESC and then press wq followed by enter.. Done.
Related
I'm building a web app where instructors provide courses and customers buy them.
I needed automation for changing courses statuses. Pretty much just checking some conditions and e.g. closing course when the current time is greater than deadline.
I'm using php-symfony, everything is dockerized. So to access my php container, I have to start docker-compose and type docker-compose exec php bash. Well in php I have a command which I can run manually, to check all the courses statuses and possibly do some changes to database if the conditions are met. But to automate this process, I decided to use crontabs. I've tested the command in cmd whether I have all the access to do such thing and it worked, so I just put it into crontab to execute every minute.
* * * * * cd /home/martin/PhpstormProjects/bp_project && sudo docker-compose exec php php bin/console courses-check >/dev/null 2>&1
The first parts gets to the project folder, the second part opens docker container and runs the command that checks courses statuses. In cmd the whole command worked. And even in /var/log/syslog which is supposed to be default crontab logging file, it gave me this output:
May 8 16:42:01 martin-ubuntu CRON[1032921]: (martin) CMD (cd /home/martin/PhpstormProjects/bp_project && sudo docker-compose exec php php bin/console courses-check >/dev/null 2>&1)
I don't see any visible errors but looking in the database, it didn't change any values while it should.
So I was thinking it could be something with docker?
I tried to add second command in crontab which is:
* * * * * cd /home && echo "hi" > a.txt
And it was saving "hi" into given file every minute.
So while the first command doesn't work, this one does. Any ideas where is the hidden problem?
change your crontab into this
* * * * * sudo docker-compose -f /home/martin/PhpstormProjects/bp_project/docker-compose.yml run --rm php sh -c ' bin/console courses-check' >/dev/null 2>&1
The below cronjob is not working, although the task itself is working when I manually run it using php artisan q:calc .
I just added the path for php and artisan files as shown below, and pasted the command in the terminal.
Am I missing something ?
* * * * * /usr/bin/php /var/www/html/sharp/artisan schedule:run >> /dev/null 2>&1
That command is a cron entry, not something you run in terminal.
For example, under the specific user you would run (depending on your environment):
$ crontab -e
And paste the above to the crontab file.
You can learn more in the docs:
https://laravel.com/docs/master/scheduling
Or by researching how to add cron entries for your specific operating system.
I have 7 different schedule commands on kernel.php and one of those is not firing when running the schedule.
kernel.php
....
$schedule->command('my:command')->hourlyAt(15); // this wont run
...
Running php artisan my:command manually on command line works fine.
Also when running the scheduler on our dev server, all commands works fine. The problem is only on production server.
There are no errors on log files.
Any ideas what might be wrong?
I'm using Laravel 5.6
UPDATED:
The problem was wrong artisan path on laravel forge scheduler
Have you add following cron entry as per your project folder path ?
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
please check with following commands
crontab -l
If not ?
open crontab by
crontab -e
add * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1 entry at the end of file
save file and run following commands
sudo service cron restart
again check with crontab -l
this command will return already set cronjob
i hope it helps :)
I want to setup a cronjob for PHP script in ubuntu
I enter this command in terminal
$ crontab -e
Then I choose nano editor which is recommended by ubuntu. Then I enter the blow line into that. Then I press control+C, it asking Y/N for save. I press Y and F2 for close.
* */2 * * * root php /var/www/html/script.php
Other things I've tried:
* */2 * * * /var/www/html/script.php
* */2 * * * root /var/www/html/script.php
After that, I restart cron using the below command.
sudo /etc/init.d/cron restart
Then I check crontab list using crontab -l, it says no cron job set for the root user.
I tried to directly create a crontab.txt file into the cron.hourly / cron.d directory with one of the above line.
I tried numerous forum and all says crontab -e then enter or create crontab file inside cron directory. Nothing is helping me. I am scratching my head.
What is the correct way to create cronjob for php script in ubuntu 16.04 & php version 7.0
Try like this to set crontab using root user,
sudo crontab -e
Do your changes via nano or vim. Finally save and quit
* */2 * * * /var/www/html/script.php
* */2 * * * root /var/www/html/script.php
No need to restart again using this sudo /etc/init.d/cron restart
Try this one (as root user):
1. sudo crontab -e
* */2 * * * php -f /var/www/html/script.php > /dev/null 2>&1
OR
* */2 * * * cd /var/www/html/; php -f script.php > /dev/null 2>&1
for crontabs runing as www-data user use command sudo crontab -u www-data -e for editing
after save crontasks will be installed automaticaly.
OR
You can create tmp_crontask_file with content * */2 * * * php -f /var/www/html/script.php > /dev/null 2>&1 AND next use sudo crontab tmp_crontask_file for install cron(s) from file (as root) sudo crontab -u www-data tmp_crontask_file (as www-data user).
Edit 1:
WARNING!
If you install cron from file (last option) content of file overwrite existing crontab.
I want to execute a PHP script on my localhost in Ubuntu. I have tried a lots of methods to apply cron but no luck!
We can set cron on our localhost through following steps:
Open crontab in your terminal:
EDITOR=gedit crontab -e
Add your cron settings at the end of your file (we are setting cron to be execute in every 2 minute in our example):
*/2 * * * * /usr/bin/php -q /path/to/phpfile.php > /dev/null
Save your cron file and run:
sudo service cron restart