CronJob not running
Finally I found the solution. Following is the solution:-
Never use relative path in python scripts to be executed via crontab.
I did something like this instead:-import os
import sys
import time, datetime
CLASS_PATH = '/srv/www/live/mainapp/classes'
SETTINGS_PATH = '/srv/www/live/foodtrade'
sys.path.insert(0, CLASS_PATH)
sys.path.insert(1,SETTINGS_PATH)
import other_py_filesNever supress the crontab code instead use mailserver and check the mail for the user. That gives clearer insights of what is going.
linux debian crontab job not executed
Oops. Guess I found the "why" or at least, the "how" :
Only renaming the job filename without ".sh" extension solved that issue.
I thought it was a Debian's bug but it isn't, as described in the other answers below.
SOLUTION: rename your script by removing all .
or +
characters from its name
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:
#!/bin/sh
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 * * * * *
.
Crontab not launching script
sudo crontab
creates a job which runs out of the crontab of root
(if you manage to configure it correctly; the syntax in root
crontabs is different). When cron
runs the job, $HOME
(and ~
if you use a shell or scripting language with tilde expansion) will refer to the home of root
etc.
You should probably simply add
0 12 * * * sudo ./Documents/Crontab_logs/Making_save.sh
to your own crontab
instead.
Notice that crontab
does not have tilde expansion at all (but we can rely on the fact that cron
will always run out of your home directory).
... Though this will still have issues, because if the script runs under sudo
and it creates new files, those files will be owned by root
, and cannot be changed by your regular user account. A better solution still is to only run the actual mount
and umount
commands with sudo
, and minimize the amount of code which runs on the privileged account, i.e. remove the sudo
from your crontab
and instead add it within the script to the individual commands which require it.
Cron and Crontab files not executed in Docker
Cron (at least in Debian) does not execute crontabs with more than 1 hardlink, see bug 647193. As Docker uses overlays, it results with more than one link to the file, so you have to touch
it in your startup script, so the link is severed:
touch /etc/crontab /etc/cron.*/*
CRON not running python script - Debian/RPi
The way how run your script causes the problem. add python
command ahead.
35 10 * * 1-5 python /home/pi/Desktop/priceChange.py
Related Topics
Ubuntu - Run Command on Start-Up with "Sudo"
Count Occurrences of a Char in Plain Text File
Randomly Pick Lines from a File Without Slurping It with Unix
What Are Stalled-Cycles-Frontend and Stalled-Cycles-Backend in 'Perf Stat' Result
Attaching and Mounting Existing Ebs Volume to Ec2 Instance Filesystem Issue
How to Wait for Server Restart Using Ansible
How to Start a Shell Without Any User Configuration
Cmd 2>&1 > Log VS Cmd > Log 2>&1
What Does "Bash:No Job Control in This Shell" Mean
Shellscript to Monitor a Log File If Keyword Triggers Then Execute a Command
Error: Gdal-Config Not Found While Installing R Dependent Packages Whereas Gdal Is Installed
Git Enter Long Passphrase for Every Push
Using Sed to Remove a Block of Text
How to Find Binary Files in a Directory
How Secure Is Storing Password with Git
Command Not Found via Ssh with Single Command, Found After Connecting to Terminal