how to get cronjob running every minute
I am following advice on crontab usage online, and I ran sudo crontab -e
, and my cron file is:
MAILTO=cchilder@mail.usf.edu
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
It doesn't mail me anything, but worse, I am checking my git log for a project I made changes to, and update_projects is not running at all. When I run it by hand it works as expected. From everything I read, I really thought cronjobs were simple, and just needed a time (5 symbols) and path to a script.
I have tried testing the script calling to ensure both the python path and script path are correct. For this, I made crontest.sh:
#!/bin/bash
/usr/bin/python /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
Crontest.sh works when called from terminal. I have no uploaded it in user crontab, sudo crontab, and still it isn't running.
User crontab:
* * * * * /home/cchilders/scripts/bash/crontest.sh
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
Sudo crontab:
MAILTO=cchilder@mail.usf.edu
* * * * * /home/cchilders/scripts/bash/crontest.sh
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
What is wrong about this, if the pathway is correct? Thank you
update_projects.py looks as follows, and is working from terminal:
#!/usr/bin/env python
import os, sys, time, subprocess
from os.path import expanduser
HOME = expanduser('~')
print 'running?
def call_sp(command, **arg_list):
#run that
p = subprocess.Popen(command, shell=True, **arg_list)
p.communicate()
def get_project_path():
i = 0
for root, dirs, files in os.walk(HOME):
if i >= 2:
return os.path.join(HOME, "projects")
i += 1
for this_dir in dirs:
if this_dir == "django_practice":
return os.path.join(HOME, "django_practice")
def update_projects(home_path):
i = 0
for root, dirs, files in os.walk(home_path):
for this_dir in dirs:
if this_dir.startswith("."):
continue
full_path = os.path.join(root, this_dir)
print full_path
time.sleep(2)
is_git_project = False
j = 0
for subroot, subdirs, subfiles in os.walk(full_path):
if j >= 1:
break
j += 1
if not ".git" in subdirs:
break
else:
is_git_project = True
if not is_git_project:
continue
d = {'cwd': full_path}
print 'git pull from {}'.format(full_path)
call_sp('git pull', **d)
time.sleep(2)
call_sp('git add -A', **d)
call_sp('git commit -m "automatic update"', **d)
call_sp('git push', **d)
dirs[:] =
ppath = get_project_path()
update_projects(ppath)
linux fedora cron
|
show 1 more comment
I am following advice on crontab usage online, and I ran sudo crontab -e
, and my cron file is:
MAILTO=cchilder@mail.usf.edu
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
It doesn't mail me anything, but worse, I am checking my git log for a project I made changes to, and update_projects is not running at all. When I run it by hand it works as expected. From everything I read, I really thought cronjobs were simple, and just needed a time (5 symbols) and path to a script.
I have tried testing the script calling to ensure both the python path and script path are correct. For this, I made crontest.sh:
#!/bin/bash
/usr/bin/python /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
Crontest.sh works when called from terminal. I have no uploaded it in user crontab, sudo crontab, and still it isn't running.
User crontab:
* * * * * /home/cchilders/scripts/bash/crontest.sh
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
Sudo crontab:
MAILTO=cchilder@mail.usf.edu
* * * * * /home/cchilders/scripts/bash/crontest.sh
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
What is wrong about this, if the pathway is correct? Thank you
update_projects.py looks as follows, and is working from terminal:
#!/usr/bin/env python
import os, sys, time, subprocess
from os.path import expanduser
HOME = expanduser('~')
print 'running?
def call_sp(command, **arg_list):
#run that
p = subprocess.Popen(command, shell=True, **arg_list)
p.communicate()
def get_project_path():
i = 0
for root, dirs, files in os.walk(HOME):
if i >= 2:
return os.path.join(HOME, "projects")
i += 1
for this_dir in dirs:
if this_dir == "django_practice":
return os.path.join(HOME, "django_practice")
def update_projects(home_path):
i = 0
for root, dirs, files in os.walk(home_path):
for this_dir in dirs:
if this_dir.startswith("."):
continue
full_path = os.path.join(root, this_dir)
print full_path
time.sleep(2)
is_git_project = False
j = 0
for subroot, subdirs, subfiles in os.walk(full_path):
if j >= 1:
break
j += 1
if not ".git" in subdirs:
break
else:
is_git_project = True
if not is_git_project:
continue
d = {'cwd': full_path}
print 'git pull from {}'.format(full_path)
call_sp('git pull', **d)
time.sleep(2)
call_sp('git add -A', **d)
call_sp('git commit -m "automatic update"', **d)
call_sp('git push', **d)
dirs[:] =
ppath = get_project_path()
update_projects(ppath)
linux fedora cron
2
1) does your script have the executable bit set? 2) does your Python script have the Python shebang line at the start?#!/usr/bin/env python
– nc4pk
Jul 7 '15 at 21:31
ya, it's got it...idk what you mean by #1
– codyc4321
Jul 7 '15 at 21:35
1
the permissions are high,-rwxrwxr-x. ... 17:32 update_projects.py
– codyc4321
Jul 7 '15 at 21:37
What happens if you put the script into your user's crontab instead of root's? (crontab -e
instead ofsudo crontab -e
)
– nc4pk
Jul 7 '15 at 21:39
1
I've had problems because thecrontab
execution environment isn't the same as a normal terminal, and doesn't always have the same PATH variable. Try launching a shell script that explicitly runspython
with its full path (returned bywhich python
), followed by the full path to your script. I also notice that you are referencing~
in the script: this will be the home directory ofroot
if you launch it usingsudo
, so unless this is really where your files reside you should do as @ncdownpat suggests and run it from your user'scrontab
.
– AFH
Jul 7 '15 at 22:04
|
show 1 more comment
I am following advice on crontab usage online, and I ran sudo crontab -e
, and my cron file is:
MAILTO=cchilder@mail.usf.edu
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
It doesn't mail me anything, but worse, I am checking my git log for a project I made changes to, and update_projects is not running at all. When I run it by hand it works as expected. From everything I read, I really thought cronjobs were simple, and just needed a time (5 symbols) and path to a script.
I have tried testing the script calling to ensure both the python path and script path are correct. For this, I made crontest.sh:
#!/bin/bash
/usr/bin/python /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
Crontest.sh works when called from terminal. I have no uploaded it in user crontab, sudo crontab, and still it isn't running.
User crontab:
* * * * * /home/cchilders/scripts/bash/crontest.sh
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
Sudo crontab:
MAILTO=cchilder@mail.usf.edu
* * * * * /home/cchilders/scripts/bash/crontest.sh
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
What is wrong about this, if the pathway is correct? Thank you
update_projects.py looks as follows, and is working from terminal:
#!/usr/bin/env python
import os, sys, time, subprocess
from os.path import expanduser
HOME = expanduser('~')
print 'running?
def call_sp(command, **arg_list):
#run that
p = subprocess.Popen(command, shell=True, **arg_list)
p.communicate()
def get_project_path():
i = 0
for root, dirs, files in os.walk(HOME):
if i >= 2:
return os.path.join(HOME, "projects")
i += 1
for this_dir in dirs:
if this_dir == "django_practice":
return os.path.join(HOME, "django_practice")
def update_projects(home_path):
i = 0
for root, dirs, files in os.walk(home_path):
for this_dir in dirs:
if this_dir.startswith("."):
continue
full_path = os.path.join(root, this_dir)
print full_path
time.sleep(2)
is_git_project = False
j = 0
for subroot, subdirs, subfiles in os.walk(full_path):
if j >= 1:
break
j += 1
if not ".git" in subdirs:
break
else:
is_git_project = True
if not is_git_project:
continue
d = {'cwd': full_path}
print 'git pull from {}'.format(full_path)
call_sp('git pull', **d)
time.sleep(2)
call_sp('git add -A', **d)
call_sp('git commit -m "automatic update"', **d)
call_sp('git push', **d)
dirs[:] =
ppath = get_project_path()
update_projects(ppath)
linux fedora cron
I am following advice on crontab usage online, and I ran sudo crontab -e
, and my cron file is:
MAILTO=cchilder@mail.usf.edu
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
It doesn't mail me anything, but worse, I am checking my git log for a project I made changes to, and update_projects is not running at all. When I run it by hand it works as expected. From everything I read, I really thought cronjobs were simple, and just needed a time (5 symbols) and path to a script.
I have tried testing the script calling to ensure both the python path and script path are correct. For this, I made crontest.sh:
#!/bin/bash
/usr/bin/python /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
Crontest.sh works when called from terminal. I have no uploaded it in user crontab, sudo crontab, and still it isn't running.
User crontab:
* * * * * /home/cchilders/scripts/bash/crontest.sh
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
Sudo crontab:
MAILTO=cchilder@mail.usf.edu
* * * * * /home/cchilders/scripts/bash/crontest.sh
* * * * * /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
What is wrong about this, if the pathway is correct? Thank you
update_projects.py looks as follows, and is working from terminal:
#!/usr/bin/env python
import os, sys, time, subprocess
from os.path import expanduser
HOME = expanduser('~')
print 'running?
def call_sp(command, **arg_list):
#run that
p = subprocess.Popen(command, shell=True, **arg_list)
p.communicate()
def get_project_path():
i = 0
for root, dirs, files in os.walk(HOME):
if i >= 2:
return os.path.join(HOME, "projects")
i += 1
for this_dir in dirs:
if this_dir == "django_practice":
return os.path.join(HOME, "django_practice")
def update_projects(home_path):
i = 0
for root, dirs, files in os.walk(home_path):
for this_dir in dirs:
if this_dir.startswith("."):
continue
full_path = os.path.join(root, this_dir)
print full_path
time.sleep(2)
is_git_project = False
j = 0
for subroot, subdirs, subfiles in os.walk(full_path):
if j >= 1:
break
j += 1
if not ".git" in subdirs:
break
else:
is_git_project = True
if not is_git_project:
continue
d = {'cwd': full_path}
print 'git pull from {}'.format(full_path)
call_sp('git pull', **d)
time.sleep(2)
call_sp('git add -A', **d)
call_sp('git commit -m "automatic update"', **d)
call_sp('git push', **d)
dirs[:] =
ppath = get_project_path()
update_projects(ppath)
linux fedora cron
linux fedora cron
edited Jul 8 '15 at 13:12
codyc4321
asked Jul 7 '15 at 21:25
codyc4321codyc4321
193111
193111
2
1) does your script have the executable bit set? 2) does your Python script have the Python shebang line at the start?#!/usr/bin/env python
– nc4pk
Jul 7 '15 at 21:31
ya, it's got it...idk what you mean by #1
– codyc4321
Jul 7 '15 at 21:35
1
the permissions are high,-rwxrwxr-x. ... 17:32 update_projects.py
– codyc4321
Jul 7 '15 at 21:37
What happens if you put the script into your user's crontab instead of root's? (crontab -e
instead ofsudo crontab -e
)
– nc4pk
Jul 7 '15 at 21:39
1
I've had problems because thecrontab
execution environment isn't the same as a normal terminal, and doesn't always have the same PATH variable. Try launching a shell script that explicitly runspython
with its full path (returned bywhich python
), followed by the full path to your script. I also notice that you are referencing~
in the script: this will be the home directory ofroot
if you launch it usingsudo
, so unless this is really where your files reside you should do as @ncdownpat suggests and run it from your user'scrontab
.
– AFH
Jul 7 '15 at 22:04
|
show 1 more comment
2
1) does your script have the executable bit set? 2) does your Python script have the Python shebang line at the start?#!/usr/bin/env python
– nc4pk
Jul 7 '15 at 21:31
ya, it's got it...idk what you mean by #1
– codyc4321
Jul 7 '15 at 21:35
1
the permissions are high,-rwxrwxr-x. ... 17:32 update_projects.py
– codyc4321
Jul 7 '15 at 21:37
What happens if you put the script into your user's crontab instead of root's? (crontab -e
instead ofsudo crontab -e
)
– nc4pk
Jul 7 '15 at 21:39
1
I've had problems because thecrontab
execution environment isn't the same as a normal terminal, and doesn't always have the same PATH variable. Try launching a shell script that explicitly runspython
with its full path (returned bywhich python
), followed by the full path to your script. I also notice that you are referencing~
in the script: this will be the home directory ofroot
if you launch it usingsudo
, so unless this is really where your files reside you should do as @ncdownpat suggests and run it from your user'scrontab
.
– AFH
Jul 7 '15 at 22:04
2
2
1) does your script have the executable bit set? 2) does your Python script have the Python shebang line at the start?
#!/usr/bin/env python
– nc4pk
Jul 7 '15 at 21:31
1) does your script have the executable bit set? 2) does your Python script have the Python shebang line at the start?
#!/usr/bin/env python
– nc4pk
Jul 7 '15 at 21:31
ya, it's got it...idk what you mean by #1
– codyc4321
Jul 7 '15 at 21:35
ya, it's got it...idk what you mean by #1
– codyc4321
Jul 7 '15 at 21:35
1
1
the permissions are high,
-rwxrwxr-x. ... 17:32 update_projects.py
– codyc4321
Jul 7 '15 at 21:37
the permissions are high,
-rwxrwxr-x. ... 17:32 update_projects.py
– codyc4321
Jul 7 '15 at 21:37
What happens if you put the script into your user's crontab instead of root's? (
crontab -e
instead of sudo crontab -e
)– nc4pk
Jul 7 '15 at 21:39
What happens if you put the script into your user's crontab instead of root's? (
crontab -e
instead of sudo crontab -e
)– nc4pk
Jul 7 '15 at 21:39
1
1
I've had problems because the
crontab
execution environment isn't the same as a normal terminal, and doesn't always have the same PATH variable. Try launching a shell script that explicitly runs python
with its full path (returned by which python
), followed by the full path to your script. I also notice that you are referencing ~
in the script: this will be the home directory of root
if you launch it using sudo
, so unless this is really where your files reside you should do as @ncdownpat suggests and run it from your user's crontab
.– AFH
Jul 7 '15 at 22:04
I've had problems because the
crontab
execution environment isn't the same as a normal terminal, and doesn't always have the same PATH variable. Try launching a shell script that explicitly runs python
with its full path (returned by which python
), followed by the full path to your script. I also notice that you are referencing ~
in the script: this will be the home directory of root
if you launch it using sudo
, so unless this is really where your files reside you should do as @ncdownpat suggests and run it from your user's crontab
.– AFH
Jul 7 '15 at 22:04
|
show 1 more comment
1 Answer
1
active
oldest
votes
Put the /usr/bin/python in the crontab entry.
* * * * * /usr/bin/python /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
surprisingly, even that didn't work. I tried it in user and sudo crontab
– codyc4321
Jul 8 '15 at 16:02
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f937568%2fhow-to-get-cronjob-running-every-minute%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Put the /usr/bin/python in the crontab entry.
* * * * * /usr/bin/python /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
surprisingly, even that didn't work. I tried it in user and sudo crontab
– codyc4321
Jul 8 '15 at 16:02
add a comment |
Put the /usr/bin/python in the crontab entry.
* * * * * /usr/bin/python /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
surprisingly, even that didn't work. I tried it in user and sudo crontab
– codyc4321
Jul 8 '15 at 16:02
add a comment |
Put the /usr/bin/python in the crontab entry.
* * * * * /usr/bin/python /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
Put the /usr/bin/python in the crontab entry.
* * * * * /usr/bin/python /home/cchilders/scripts/python/scripts-in-progress/update_projects.py
answered Jul 8 '15 at 13:39
JackJack
579210
579210
surprisingly, even that didn't work. I tried it in user and sudo crontab
– codyc4321
Jul 8 '15 at 16:02
add a comment |
surprisingly, even that didn't work. I tried it in user and sudo crontab
– codyc4321
Jul 8 '15 at 16:02
surprisingly, even that didn't work. I tried it in user and sudo crontab
– codyc4321
Jul 8 '15 at 16:02
surprisingly, even that didn't work. I tried it in user and sudo crontab
– codyc4321
Jul 8 '15 at 16:02
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f937568%2fhow-to-get-cronjob-running-every-minute%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
1) does your script have the executable bit set? 2) does your Python script have the Python shebang line at the start?
#!/usr/bin/env python
– nc4pk
Jul 7 '15 at 21:31
ya, it's got it...idk what you mean by #1
– codyc4321
Jul 7 '15 at 21:35
1
the permissions are high,
-rwxrwxr-x. ... 17:32 update_projects.py
– codyc4321
Jul 7 '15 at 21:37
What happens if you put the script into your user's crontab instead of root's? (
crontab -e
instead ofsudo crontab -e
)– nc4pk
Jul 7 '15 at 21:39
1
I've had problems because the
crontab
execution environment isn't the same as a normal terminal, and doesn't always have the same PATH variable. Try launching a shell script that explicitly runspython
with its full path (returned bywhich python
), followed by the full path to your script. I also notice that you are referencing~
in the script: this will be the home directory ofroot
if you launch it usingsudo
, so unless this is really where your files reside you should do as @ncdownpat suggests and run it from your user'scrontab
.– AFH
Jul 7 '15 at 22:04