This is my crontab file (after crontab -e):
50 6,14,22 * * * php /var/www/web_hdef/public/artisan run:handler
0 6,14,22 * * * php /var/www/web_hdef/public/artisan run:endomondo
30 6,14,22 * * * php /var/www/web_hdef/public/artisan run:update
but it doesn't run and after crontab -l in command line I got:
hp /var/www/web_hdef/public/artisan run:updatedo(8)
I ran commands separately a they works
Most likely php executable is not in $PATH of user running the script. Use absolute path
in nano editor I didn't see all of signs in text file, when I openned it in vim editor, I saw that there are extra white spaces. I removed it and now it works.
Related
I have a scree.php file in the path:
xxx/.../Home/scree.php
I want to execute it per 5 minutes, and make sure it is thread-safety. How to do that?
I am under XShell.
It can be done using crontab.
Type "crontab -e" in your terminal.
Paste in the following code:
*/5 * * * * php /Home/scree.php
Exit out of your editor.
Learn more about crontab here.
You can edit the crontab in XShell:
crontab -e
Then in the file, you should add the code:
*/5 * * * * root usr/bin/php xxx/.../Home/scree.php
Then esc :wq out of the file.
If it shows:
crontab: installing new crontab
means success.
I have a pretty simple db back-up script that runs perfectly from shell.
php /home/db_backup/db_backup.php
When I attempt to add a Crontab, I get the vague 'Bad Command errors in crontab, can't install."
I've tried w/ php and full path to php.
which php
returns /usr/bin/php
* 1 * * * php /home/db_backup/db_backup.php
* 1 * * * /usr/bin/php /home/db_backup/db_backup.php
Both return the same error.
Centos 6.6. logged in as root. Editing crontab thusly
crontab -e
Spent too many hours trying to get this working. What am I missing?
I bet your problem is when editing the crontab file not with the commands itself.
Be sure to let a blank line at the end of file.
I mean the cursor must be in an empty line after the last entry.
I have a script to backup my database at /home/<user>/bin/dbbackup. The script is executable by all users, and owned by me. The files /etc/cron.allow and /etc/cron.deny do not exist.
In my crontab I have the following lines (including a new blank line after the last line of code):
#reboot /home/<user>/.dropbox-dist/dropboxd
30 2 * * * bash /home/<user>/bin/dbbackup
However, cron is not running my dbbackup script. When I run a manual test of the script it works. When I run this test on the command line: * * * * * /bin/echo "cron works" >> ~/file I get the following error:
No command 'dbbackup' found, did you mean:
Command 'dvbackup' from package 'dvbackup' (universe)
Command 'tdbbackup' from package 'tdb-tools' (main)
dbbackup: command not found
My server is running Ubuntu Trusty. Any help please?
As the comments noted, it appears that amiga_os needed remove the reference to bash in the line.
30 2 * * * bash /home/<user>/bin/dbbackup
Should be.
30 2 * * * /home/<user>/bin/dbbackup
I usually just call scripts from their path and use "#!/bin/bash" (or wherever your bash lives) as the first line of the script. It appears the amiga_os had already done this, which is good. I don't like putting sentences into cron because it makes me nervous.
I think it was a path issue as cron executes as the user but does not read the bash profile and therefore does not work exactly like it would under your shell as it might not have access to your $PATH.
I have added a script in crontab for every 30 minutes. The line goes as follows:
*/30 * * * * root perl /root/perl.pl
The above script has a execution of system command 'top' and it gets printed in a log file.
If I run it manually it runs fine. But while running it via crontab, it does not show up the desired results. Please can somebody help me with this. Thank you.
The command in the above perl script is:
$top = `sudo top`;
The error I am getting is:
sudo: sorry, you must have a tty to run sudo
I changed my command from sudo to visudo. But still the problem remains.
You should use the full path in cron (and use which perl to find the full path):
*/30 * * * * root /usr/bin/perl /root/perl.pl
OR better yet, make the script executable using chmod +x, and add the interpreter to the beginning of the script #!/usr/bin/perl -w and call it directly from cron
*/30 * * * * root /root/perl.pl
Also if there is a problem in the perl script, you could output the result from cron like this
*/30 * * * * root /root/perl.pl > /tmp/myscript.log
You should look into the requiretty setting with regard to visudo. Look for a line that reads Defaults requiretty. You could try commenting it out, but you will be sacrificing some security. See man sudoers.
You could also try running top in batch mode with one iteration:
$top = `sudo top -bn1`;
Batch mode option is for sending output to other programs.
I'm trying to execute a shell script from cron on Freebsd.
To test whether crontab is working at all, I wrote the line
* * * * * echo "Hello" > /home/myuser/logile
and it work fine.
But when trying to execute any script it doesn't do anything, not even an error. (In the script I tried to run is just the same echo command)
Below is the output of crontab -l:
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
HOME=/home/myuser
MAILTO=myuser
* * * * * /home/myuser/shellscript.sh > /home/myuser/logfile
Why is the script not getting executed, although crontab is obviously running?
Permission for all files are set to rwxr-xr-x.
* * * * * /bin/sh /home/myuser/shellscript.sh
or
* * * * * /bin/bash /home/myuser/shellscript.sh
worked for me in Macosx 10.6 as rootuser
Have you checked that the command line has a linefeed/CR at the end of the line? I struggled for hours trying to find a reason for non-executing php script on cron when I simply hadn't pressed enter at the end of the line when I edited the cron jobs with crontab -e :-)
Have you checked /var/log/cron for clues?
Have you tried
* * * * * /bin/sh /home/myuser/shellscript.sh > /home/myuser/logfile
cron sends any errors via email to owner of the crontab file (often "root" so you might check that account's email). To have any errors mailed to "crontabOnFreebsd" put:
MAILTO=crontabOnFreebsd
in your crontab (near the top).
For more info issue this command:
man 5 crontab
If you are getting an error, then your logfile might not capture it, try this:
* * * * * /home/myuser/shellscript.sh > /home/myuser/logfile 2> /home/myuser/errorfile
Its been a while since I did any cron stuff; but things that always used to get me:
Environment variables not been set: generally I found it necessary to set up full paths (even to things like 'cat') to all commands [or at least set ENV variables within the script itself].
Ensure the user who owns the script etc is really the user which is running the script: this might not be the same user when you test from the interactive shell. Same goes for the directories/files that the script might write to.
Also: check the email for the root user - you might find that the errors have been diverted to the inbox, which may help you troubleshoot this further.