Python script not running correctly when launched with crontab
I'm running a telegram bot on my Raspberry Pi 3. When I run it in my console or using Thonny, everything runs smoothly.
python3 /home/pi/Documents/telegrambot.py
The problem occurs when I set the program to start on boot.
sudo crontab -e
[last line] @reboot sudo python3 /home/pi/Documents/telegrambot.py &
I know that the code is running because I set the bot to send me "I'm online" and it answer me if the reply isn't related to sending images... but when I send to it /tempgraph, it should answer with the the picture of its readings.
But I only get the sensor's name and no image at all.
...
chatHist = readCommandHistory(db,chat_id,1)
lastCommand = chatHist[0]['msg']
choice = command.split(".")
if command in lastCommand and len(choice) <= 2:
Fonte = re.search('(s|n)'+str(command.split('.')[0])+')s(.*)', lastCommand).group(2)
bot.sendMessage(chat_id, Fonte) #this works
if len(choice) == 1:
table = sdc.readTableServer(db, senstable, 'Fonte', Fonte)
for sensor in table.Sensor.unique():
bot.sendMessage(chat_id, sensor)
tbl = table[table.Sensor == sensor]
#until here everything is ok
for ts in tiposensores:
try:
gop.plotSetup(tbl[['Data',ts]])
#save the image in the folter ... Images/Imagem.png,
#but only works when not on stratup...
bot.sendPhoto(chat_id,open('/home/pi/Documents/Images/Imagem.png','rb'))
pif.cleanImages()
except OSError:
pass
...
@edit:
I found out that the problem happens after i call
gop.plotSetup(tbl[['Data',ts]])
inside the plotSetup function, in this step:
f= plt.figure(figsize=(12, 9))
This is the first time that i use the variable f inside the function.
raspbian pi-3 python boot
New contributor
SWoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 1 more comment
I'm running a telegram bot on my Raspberry Pi 3. When I run it in my console or using Thonny, everything runs smoothly.
python3 /home/pi/Documents/telegrambot.py
The problem occurs when I set the program to start on boot.
sudo crontab -e
[last line] @reboot sudo python3 /home/pi/Documents/telegrambot.py &
I know that the code is running because I set the bot to send me "I'm online" and it answer me if the reply isn't related to sending images... but when I send to it /tempgraph, it should answer with the the picture of its readings.
But I only get the sensor's name and no image at all.
...
chatHist = readCommandHistory(db,chat_id,1)
lastCommand = chatHist[0]['msg']
choice = command.split(".")
if command in lastCommand and len(choice) <= 2:
Fonte = re.search('(s|n)'+str(command.split('.')[0])+')s(.*)', lastCommand).group(2)
bot.sendMessage(chat_id, Fonte) #this works
if len(choice) == 1:
table = sdc.readTableServer(db, senstable, 'Fonte', Fonte)
for sensor in table.Sensor.unique():
bot.sendMessage(chat_id, sensor)
tbl = table[table.Sensor == sensor]
#until here everything is ok
for ts in tiposensores:
try:
gop.plotSetup(tbl[['Data',ts]])
#save the image in the folter ... Images/Imagem.png,
#but only works when not on stratup...
bot.sendPhoto(chat_id,open('/home/pi/Documents/Images/Imagem.png','rb'))
pif.cleanImages()
except OSError:
pass
...
@edit:
I found out that the problem happens after i call
gop.plotSetup(tbl[['Data',ts]])
inside the plotSetup function, in this step:
f= plt.figure(figsize=(12, 9))
This is the first time that i use the variable f inside the function.
raspbian pi-3 python boot
New contributor
SWoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Does thisgop.PlotSetupgenerate a picture and store it on disk?
– Mark Smith
11 hours ago
Edit the crontab without "sudo":$ crontab -e
– Benyamin Jafari
8 hours ago
@MarkSmith, yeah it does! I'll add the last line of this function in the post.
– SWoto
7 hours ago
@BenyaminJafari, tried this too, everything runs in the same way as before (sending pictures still not working) =(
– SWoto
7 hours ago
Debug the python script to a log file and check the errors after booting. Make sure you use chmod -R, recursive.
– Pedro Lobito
3 hours ago
|
show 1 more comment
I'm running a telegram bot on my Raspberry Pi 3. When I run it in my console or using Thonny, everything runs smoothly.
python3 /home/pi/Documents/telegrambot.py
The problem occurs when I set the program to start on boot.
sudo crontab -e
[last line] @reboot sudo python3 /home/pi/Documents/telegrambot.py &
I know that the code is running because I set the bot to send me "I'm online" and it answer me if the reply isn't related to sending images... but when I send to it /tempgraph, it should answer with the the picture of its readings.
But I only get the sensor's name and no image at all.
...
chatHist = readCommandHistory(db,chat_id,1)
lastCommand = chatHist[0]['msg']
choice = command.split(".")
if command in lastCommand and len(choice) <= 2:
Fonte = re.search('(s|n)'+str(command.split('.')[0])+')s(.*)', lastCommand).group(2)
bot.sendMessage(chat_id, Fonte) #this works
if len(choice) == 1:
table = sdc.readTableServer(db, senstable, 'Fonte', Fonte)
for sensor in table.Sensor.unique():
bot.sendMessage(chat_id, sensor)
tbl = table[table.Sensor == sensor]
#until here everything is ok
for ts in tiposensores:
try:
gop.plotSetup(tbl[['Data',ts]])
#save the image in the folter ... Images/Imagem.png,
#but only works when not on stratup...
bot.sendPhoto(chat_id,open('/home/pi/Documents/Images/Imagem.png','rb'))
pif.cleanImages()
except OSError:
pass
...
@edit:
I found out that the problem happens after i call
gop.plotSetup(tbl[['Data',ts]])
inside the plotSetup function, in this step:
f= plt.figure(figsize=(12, 9))
This is the first time that i use the variable f inside the function.
raspbian pi-3 python boot
New contributor
SWoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm running a telegram bot on my Raspberry Pi 3. When I run it in my console or using Thonny, everything runs smoothly.
python3 /home/pi/Documents/telegrambot.py
The problem occurs when I set the program to start on boot.
sudo crontab -e
[last line] @reboot sudo python3 /home/pi/Documents/telegrambot.py &
I know that the code is running because I set the bot to send me "I'm online" and it answer me if the reply isn't related to sending images... but when I send to it /tempgraph, it should answer with the the picture of its readings.
But I only get the sensor's name and no image at all.
...
chatHist = readCommandHistory(db,chat_id,1)
lastCommand = chatHist[0]['msg']
choice = command.split(".")
if command in lastCommand and len(choice) <= 2:
Fonte = re.search('(s|n)'+str(command.split('.')[0])+')s(.*)', lastCommand).group(2)
bot.sendMessage(chat_id, Fonte) #this works
if len(choice) == 1:
table = sdc.readTableServer(db, senstable, 'Fonte', Fonte)
for sensor in table.Sensor.unique():
bot.sendMessage(chat_id, sensor)
tbl = table[table.Sensor == sensor]
#until here everything is ok
for ts in tiposensores:
try:
gop.plotSetup(tbl[['Data',ts]])
#save the image in the folter ... Images/Imagem.png,
#but only works when not on stratup...
bot.sendPhoto(chat_id,open('/home/pi/Documents/Images/Imagem.png','rb'))
pif.cleanImages()
except OSError:
pass
...
@edit:
I found out that the problem happens after i call
gop.plotSetup(tbl[['Data',ts]])
inside the plotSetup function, in this step:
f= plt.figure(figsize=(12, 9))
This is the first time that i use the variable f inside the function.
raspbian pi-3 python boot
raspbian pi-3 python boot
New contributor
SWoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SWoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 hours ago
SWoto
New contributor
SWoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 11 hours ago
SWotoSWoto
142
142
New contributor
SWoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SWoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
SWoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Does thisgop.PlotSetupgenerate a picture and store it on disk?
– Mark Smith
11 hours ago
Edit the crontab without "sudo":$ crontab -e
– Benyamin Jafari
8 hours ago
@MarkSmith, yeah it does! I'll add the last line of this function in the post.
– SWoto
7 hours ago
@BenyaminJafari, tried this too, everything runs in the same way as before (sending pictures still not working) =(
– SWoto
7 hours ago
Debug the python script to a log file and check the errors after booting. Make sure you use chmod -R, recursive.
– Pedro Lobito
3 hours ago
|
show 1 more comment
Does thisgop.PlotSetupgenerate a picture and store it on disk?
– Mark Smith
11 hours ago
Edit the crontab without "sudo":$ crontab -e
– Benyamin Jafari
8 hours ago
@MarkSmith, yeah it does! I'll add the last line of this function in the post.
– SWoto
7 hours ago
@BenyaminJafari, tried this too, everything runs in the same way as before (sending pictures still not working) =(
– SWoto
7 hours ago
Debug the python script to a log file and check the errors after booting. Make sure you use chmod -R, recursive.
– Pedro Lobito
3 hours ago
Does this
gop.PlotSetup generate a picture and store it on disk?– Mark Smith
11 hours ago
Does this
gop.PlotSetup generate a picture and store it on disk?– Mark Smith
11 hours ago
Edit the crontab without "sudo":
$ crontab -e– Benyamin Jafari
8 hours ago
Edit the crontab without "sudo":
$ crontab -e– Benyamin Jafari
8 hours ago
@MarkSmith, yeah it does! I'll add the last line of this function in the post.
– SWoto
7 hours ago
@MarkSmith, yeah it does! I'll add the last line of this function in the post.
– SWoto
7 hours ago
@BenyaminJafari, tried this too, everything runs in the same way as before (sending pictures still not working) =(
– SWoto
7 hours ago
@BenyaminJafari, tried this too, everything runs in the same way as before (sending pictures still not working) =(
– SWoto
7 hours ago
Debug the python script to a log file and check the errors after booting. Make sure you use chmod -R, recursive.
– Pedro Lobito
3 hours ago
Debug the python script to a log file and check the errors after booting. Make sure you use chmod -R, recursive.
– Pedro Lobito
3 hours ago
|
show 1 more comment
2 Answers
2
active
oldest
votes
Try this:
$ sudo chmod 777 /home/pi/Documents/Images
After you've done that, re-boot to check if that fixes it.
If not, try changing your crontab entry to this:
@reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1)
You should also consider adding a debug statement to your Python code to collect and save any errors that are thrown during execution.
I thied this with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
@SWoto: I'll edit my answer; check back shortly. In the meantime, what is the purpose of the stuff on your crontab: [Ctrl+X -> Y -> Enter] ?
– Seamus
6 hours ago
@Seamnu: i tried what u said and it didn't solve the problem. But i've some more info (i'll add it in the post too). The problem happens inside this funciton: gop.plotSetup(tbl[['Data',ts]]), right here f= plt.figure(figsize=(12, 9)). This is the first time using the variable 'f' and plt comes from import matplotlib.pyplot as plt. So the problem lies in the plt, not in the folter permission, because the saving step is the last thing inside the plotSetup function.
– SWoto
2 hours ago
add a comment |
This might be a permission problem. When running under the user's (your) credentials it works and when under the crontab's credentials is does not.
Try a test: WRT to your images, temporarily open permissions to all images files and the associated directory and see if the application works when run by the crontab.
Don't leave the permissions opened to all as it is a security risk.
I thied this ($ sudo chmod 777 /home/pi/Documents/Images ) with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
There may also be an issue with the path you use and the path which is used when running a crontab job. But since you indicated the python script was running I didn't mention it. Also, use complete paths to files avoiding problems associated with variables like "$HOME" or paths which start with "~".
– st2000
3 hours ago
just eddited the post. I found that the problem lies here: f= plt.figure(figsize=(12, 9)), inside the plotSetup function. I tried the complete paths too, like u and Seamus said: reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1), but the problem persists.
– SWoto
2 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("schematics", function () {
StackExchange.schematics.init();
});
}, "cicuitlab");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "447"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
});
}
});
SWoto is a new contributor. Be nice, and check out our Code of Conduct.
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%2fraspberrypi.stackexchange.com%2fquestions%2f95726%2fpython-script-not-running-correctly-when-launched-with-crontab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this:
$ sudo chmod 777 /home/pi/Documents/Images
After you've done that, re-boot to check if that fixes it.
If not, try changing your crontab entry to this:
@reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1)
You should also consider adding a debug statement to your Python code to collect and save any errors that are thrown during execution.
I thied this with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
@SWoto: I'll edit my answer; check back shortly. In the meantime, what is the purpose of the stuff on your crontab: [Ctrl+X -> Y -> Enter] ?
– Seamus
6 hours ago
@Seamnu: i tried what u said and it didn't solve the problem. But i've some more info (i'll add it in the post too). The problem happens inside this funciton: gop.plotSetup(tbl[['Data',ts]]), right here f= plt.figure(figsize=(12, 9)). This is the first time using the variable 'f' and plt comes from import matplotlib.pyplot as plt. So the problem lies in the plt, not in the folter permission, because the saving step is the last thing inside the plotSetup function.
– SWoto
2 hours ago
add a comment |
Try this:
$ sudo chmod 777 /home/pi/Documents/Images
After you've done that, re-boot to check if that fixes it.
If not, try changing your crontab entry to this:
@reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1)
You should also consider adding a debug statement to your Python code to collect and save any errors that are thrown during execution.
I thied this with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
@SWoto: I'll edit my answer; check back shortly. In the meantime, what is the purpose of the stuff on your crontab: [Ctrl+X -> Y -> Enter] ?
– Seamus
6 hours ago
@Seamnu: i tried what u said and it didn't solve the problem. But i've some more info (i'll add it in the post too). The problem happens inside this funciton: gop.plotSetup(tbl[['Data',ts]]), right here f= plt.figure(figsize=(12, 9)). This is the first time using the variable 'f' and plt comes from import matplotlib.pyplot as plt. So the problem lies in the plt, not in the folter permission, because the saving step is the last thing inside the plotSetup function.
– SWoto
2 hours ago
add a comment |
Try this:
$ sudo chmod 777 /home/pi/Documents/Images
After you've done that, re-boot to check if that fixes it.
If not, try changing your crontab entry to this:
@reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1)
You should also consider adding a debug statement to your Python code to collect and save any errors that are thrown during execution.
Try this:
$ sudo chmod 777 /home/pi/Documents/Images
After you've done that, re-boot to check if that fixes it.
If not, try changing your crontab entry to this:
@reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1)
You should also consider adding a debug statement to your Python code to collect and save any errors that are thrown during execution.
edited 6 hours ago
answered 8 hours ago
SeamusSeamus
2,8071321
2,8071321
I thied this with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
@SWoto: I'll edit my answer; check back shortly. In the meantime, what is the purpose of the stuff on your crontab: [Ctrl+X -> Y -> Enter] ?
– Seamus
6 hours ago
@Seamnu: i tried what u said and it didn't solve the problem. But i've some more info (i'll add it in the post too). The problem happens inside this funciton: gop.plotSetup(tbl[['Data',ts]]), right here f= plt.figure(figsize=(12, 9)). This is the first time using the variable 'f' and plt comes from import matplotlib.pyplot as plt. So the problem lies in the plt, not in the folter permission, because the saving step is the last thing inside the plotSetup function.
– SWoto
2 hours ago
add a comment |
I thied this with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
@SWoto: I'll edit my answer; check back shortly. In the meantime, what is the purpose of the stuff on your crontab: [Ctrl+X -> Y -> Enter] ?
– Seamus
6 hours ago
@Seamnu: i tried what u said and it didn't solve the problem. But i've some more info (i'll add it in the post too). The problem happens inside this funciton: gop.plotSetup(tbl[['Data',ts]]), right here f= plt.figure(figsize=(12, 9)). This is the first time using the variable 'f' and plt comes from import matplotlib.pyplot as plt. So the problem lies in the plt, not in the folter permission, because the saving step is the last thing inside the plotSetup function.
– SWoto
2 hours ago
I thied this with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
I thied this with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
@SWoto: I'll edit my answer; check back shortly. In the meantime, what is the purpose of the stuff on your crontab: [Ctrl+X -> Y -> Enter] ?
– Seamus
6 hours ago
@SWoto: I'll edit my answer; check back shortly. In the meantime, what is the purpose of the stuff on your crontab: [Ctrl+X -> Y -> Enter] ?
– Seamus
6 hours ago
@Seamnu: i tried what u said and it didn't solve the problem. But i've some more info (i'll add it in the post too). The problem happens inside this funciton: gop.plotSetup(tbl[['Data',ts]]), right here f= plt.figure(figsize=(12, 9)). This is the first time using the variable 'f' and plt comes from import matplotlib.pyplot as plt. So the problem lies in the plt, not in the folter permission, because the saving step is the last thing inside the plotSetup function.
– SWoto
2 hours ago
@Seamnu: i tried what u said and it didn't solve the problem. But i've some more info (i'll add it in the post too). The problem happens inside this funciton: gop.plotSetup(tbl[['Data',ts]]), right here f= plt.figure(figsize=(12, 9)). This is the first time using the variable 'f' and plt comes from import matplotlib.pyplot as plt. So the problem lies in the plt, not in the folter permission, because the saving step is the last thing inside the plotSetup function.
– SWoto
2 hours ago
add a comment |
This might be a permission problem. When running under the user's (your) credentials it works and when under the crontab's credentials is does not.
Try a test: WRT to your images, temporarily open permissions to all images files and the associated directory and see if the application works when run by the crontab.
Don't leave the permissions opened to all as it is a security risk.
I thied this ($ sudo chmod 777 /home/pi/Documents/Images ) with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
There may also be an issue with the path you use and the path which is used when running a crontab job. But since you indicated the python script was running I didn't mention it. Also, use complete paths to files avoiding problems associated with variables like "$HOME" or paths which start with "~".
– st2000
3 hours ago
just eddited the post. I found that the problem lies here: f= plt.figure(figsize=(12, 9)), inside the plotSetup function. I tried the complete paths too, like u and Seamus said: reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1), but the problem persists.
– SWoto
2 hours ago
add a comment |
This might be a permission problem. When running under the user's (your) credentials it works and when under the crontab's credentials is does not.
Try a test: WRT to your images, temporarily open permissions to all images files and the associated directory and see if the application works when run by the crontab.
Don't leave the permissions opened to all as it is a security risk.
I thied this ($ sudo chmod 777 /home/pi/Documents/Images ) with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
There may also be an issue with the path you use and the path which is used when running a crontab job. But since you indicated the python script was running I didn't mention it. Also, use complete paths to files avoiding problems associated with variables like "$HOME" or paths which start with "~".
– st2000
3 hours ago
just eddited the post. I found that the problem lies here: f= plt.figure(figsize=(12, 9)), inside the plotSetup function. I tried the complete paths too, like u and Seamus said: reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1), but the problem persists.
– SWoto
2 hours ago
add a comment |
This might be a permission problem. When running under the user's (your) credentials it works and when under the crontab's credentials is does not.
Try a test: WRT to your images, temporarily open permissions to all images files and the associated directory and see if the application works when run by the crontab.
Don't leave the permissions opened to all as it is a security risk.
This might be a permission problem. When running under the user's (your) credentials it works and when under the crontab's credentials is does not.
Try a test: WRT to your images, temporarily open permissions to all images files and the associated directory and see if the application works when run by the crontab.
Don't leave the permissions opened to all as it is a security risk.
answered 10 hours ago
st2000st2000
36414
36414
I thied this ($ sudo chmod 777 /home/pi/Documents/Images ) with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
There may also be an issue with the path you use and the path which is used when running a crontab job. But since you indicated the python script was running I didn't mention it. Also, use complete paths to files avoiding problems associated with variables like "$HOME" or paths which start with "~".
– st2000
3 hours ago
just eddited the post. I found that the problem lies here: f= plt.figure(figsize=(12, 9)), inside the plotSetup function. I tried the complete paths too, like u and Seamus said: reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1), but the problem persists.
– SWoto
2 hours ago
add a comment |
I thied this ($ sudo chmod 777 /home/pi/Documents/Images ) with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
There may also be an issue with the path you use and the path which is used when running a crontab job. But since you indicated the python script was running I didn't mention it. Also, use complete paths to files avoiding problems associated with variables like "$HOME" or paths which start with "~".
– st2000
3 hours ago
just eddited the post. I found that the problem lies here: f= plt.figure(figsize=(12, 9)), inside the plotSetup function. I tried the complete paths too, like u and Seamus said: reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1), but the problem persists.
– SWoto
2 hours ago
I thied this ($ sudo chmod 777 /home/pi/Documents/Images ) with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
I thied this ($ sudo chmod 777 /home/pi/Documents/Images ) with no success. =/. Also changed the crontab code to: @reboot python3 /home/pi/Documents/telegrambot.py & /home/pi/Desktop/log.txt >&1 to get some error log, but nothing happened.
– SWoto
7 hours ago
There may also be an issue with the path you use and the path which is used when running a crontab job. But since you indicated the python script was running I didn't mention it. Also, use complete paths to files avoiding problems associated with variables like "$HOME" or paths which start with "~".
– st2000
3 hours ago
There may also be an issue with the path you use and the path which is used when running a crontab job. But since you indicated the python script was running I didn't mention it. Also, use complete paths to files avoiding problems associated with variables like "$HOME" or paths which start with "~".
– st2000
3 hours ago
just eddited the post. I found that the problem lies here: f= plt.figure(figsize=(12, 9)), inside the plotSetup function. I tried the complete paths too, like u and Seamus said: reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1), but the problem persists.
– SWoto
2 hours ago
just eddited the post. I found that the problem lies here: f= plt.figure(figsize=(12, 9)), inside the plotSetup function. I tried the complete paths too, like u and Seamus said: reboot ( /bin/sleep 30; /usr/bin/sudo /usr/bin/python3 /home/pi/Documents/telegrambot.py >> /home/pi/Desktop/log.txt 2>&1), but the problem persists.
– SWoto
2 hours ago
add a comment |
SWoto is a new contributor. Be nice, and check out our Code of Conduct.
SWoto is a new contributor. Be nice, and check out our Code of Conduct.
SWoto is a new contributor. Be nice, and check out our Code of Conduct.
SWoto is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Raspberry Pi Stack Exchange!
- 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%2fraspberrypi.stackexchange.com%2fquestions%2f95726%2fpython-script-not-running-correctly-when-launched-with-crontab%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
Does this
gop.PlotSetupgenerate a picture and store it on disk?– Mark Smith
11 hours ago
Edit the crontab without "sudo":
$ crontab -e– Benyamin Jafari
8 hours ago
@MarkSmith, yeah it does! I'll add the last line of this function in the post.
– SWoto
7 hours ago
@BenyaminJafari, tried this too, everything runs in the same way as before (sending pictures still not working) =(
– SWoto
7 hours ago
Debug the python script to a log file and check the errors after booting. Make sure you use chmod -R, recursive.
– Pedro Lobito
3 hours ago