cronjob does not execute a script that works fine standalone
As seen in comments, the problem is that you are not defining what program should be used to execute the script. Take into account that a cronjob is executed in a tiny environment; there, not much can be assumed. This is why we define full paths, etc.
So you need to say something like:
1 * * * * /bin/sh /var/www/html/dbsync/dbsync.sh /var/www/html/dbsync
/bin/sh being the binary you want to use to execute the script.
Otherwise, you can set execution permissions to the script and add a shell-script header telling it what interpreter to use:
If you do this, adding the path of the binary is not necessary.
From Troubleshooting common issues with cron jobs:
Using relative paths. If your cron job is executing a script of some
kind, you must be sure to use only absolute paths inside that script.
For example, if your script is located at /path/to/script.phpand
you're trying to open a file called file.php in the same directory,
you cannot use a relative path such as fopen(file.php). The file must
be called from its absolute path, like this: fopen(/path/to/file.php).
This is because cron jobs do not necessarily run from the directory in
which the script is located, so all paths must be called specifically.
Also, I understand you want to run this every minute. If so,
1 * * * * won't do. Intead, it will run at every 1st minute past every hour. So if you want to run it every minute, say
* * * * *.
Cron job with script sh is not executed but job is running in cron log
Cron doesn't inherit your environement.
$HOME is not set when you run your cron, thus the
~ is not interpoled.
You can set it like this:
18 14 * * * rm ~/Rendu/test_cron/lol.py
bash script runs standalone but not with cron
my issue is just a typo, filename was wrong.
thanks to Barmer who helped me output cron log that let to fixing the problem
Shell script doesn't run properly while running from crontab
Apparently crontab was running my script several times. So I tried to use different locking mechanisms to put a lock around my scrip but only using flock worked for me. In my crontab I added this line:
* * * * * /usr/bin/flock -n /tmp/ms.lockfile /bin/bash /path/to/my/script/myShellScript.sh
How to Send a HTML Email With the Bash Command "Sendmail"
What Are the Calling Conventions For Unix & Linux System Calls (And User-Space Functions) on I386 and X86-64
Defining a Variable With or Without Export
What Is the Meaning of "Posix"
Exploring Docker Container'S File System
Bash While Read Loop Extremely Slow Compared to Cat, Why
Bluetooth Low Energy: Listening For Notifications/Indications in Linux
Modify Qt Gui from Background Worker Thread
Free Git Server With Web Gui a La Bitbucket/Github
Print a File, Skipping the First X Lines, in Bash
32-Bit Absolute Addresses No Longer Allowed in X86-64 Linux
Best Practices When Running Node.Js With Port 80 (Ubuntu/Linode)
What Does $@ Mean in a Shell Script
Cronjob Does Not Execute a Script That Works Fine Standalone
Bash Script Processing Limited Number of Commands in Parallel