Skip to main content
added 442 characters in body
Source Link
bjk116
  • 121
  • 5

I have a script /home/projects/temperature_logger/analyze.py that does some work on a temp.log file, which is really a csv of a date and the current raspberry pi temperature. This python script also logs the results to a .log file. Calling it from the command line like sudo python3 analyze.py works as expected, but for some reason I cannot get it ot work with crontab.

I have run sudo chmod +x analyze.py as well as sudo chmod ugo+w analyze.py.

My whereis python3 says /usr/bin/python3. The shebang at the top of my analyze.py script is #!/usr/bin/python3.

My crontab script is * * * * * /usr/bin/python3 /home/projects/temperature_logger/analyze.py

For testing purposes all I have actually running right now is

if __name__ == '__main__':
    logging.info("running file!")

in my analyze.py but I do not see this getting populated to my log file unless I manually call sudo python3 analyze.py from within the directory.

What am I doing wrong here? The syslogs don't seem to indicate anything wrong but perhaps I don't understand them? Apologies for the picture I am unsure how to copy from the PuTTy terminal enter image description here

Update: I added all permissions for my user ubuntu with sudo chmod -R a+rwx /home/projects/temperature_logger. I then changed the crontab, cleared out my root cron and put the call to the python script under ubuntu's cron file. I do see this reflected under the syslog now enter image description here

It does not seem to indicate any error. However, the script which when I call it with python3 analyze.py it does write properly to my scripts.log file, but when it's called from the cron, which it says is running the syslog - I don't see anything logged.

Solved: So this was due to me misunderstanding waht the home directory for my user account was and what the current working directory of the script was. In my analyze.py script I had logging.basicConfig(filename='scripts.log', ...), which when I ran from the directory with sudo, wrote to /home/projects/temperature_logger/scripts.log, but when it was called from my user's cron file, it wrote to /home/ubuntu/scripts.log.

I have a script /home/projects/temperature_logger/analyze.py that does some work on a temp.log file, which is really a csv of a date and the current raspberry pi temperature. This python script also logs the results to a .log file. Calling it from the command line like sudo python3 analyze.py works as expected, but for some reason I cannot get it ot work with crontab.

I have run sudo chmod +x analyze.py as well as sudo chmod ugo+w analyze.py.

My whereis python3 says /usr/bin/python3. The shebang at the top of my analyze.py script is #!/usr/bin/python3.

My crontab script is * * * * * /usr/bin/python3 /home/projects/temperature_logger/analyze.py

For testing purposes all I have actually running right now is

if __name__ == '__main__':
    logging.info("running file!")

in my analyze.py but I do not see this getting populated to my log file unless I manually call sudo python3 analyze.py from within the directory.

What am I doing wrong here? The syslogs don't seem to indicate anything wrong but perhaps I don't understand them? Apologies for the picture I am unsure how to copy from the PuTTy terminal enter image description here

Update: I added all permissions for my user ubuntu with sudo chmod -R a+rwx /home/projects/temperature_logger. I then changed the crontab, cleared out my root cron and put the call to the python script under ubuntu's cron file. I do see this reflected under the syslog now enter image description here

It does not seem to indicate any error. However, the script which when I call it with python3 analyze.py it does write properly to my scripts.log file, but when it's called from the cron, which it says is running the syslog - I don't see anything logged.

I have a script /home/projects/temperature_logger/analyze.py that does some work on a temp.log file, which is really a csv of a date and the current raspberry pi temperature. This python script also logs the results to a .log file. Calling it from the command line like sudo python3 analyze.py works as expected, but for some reason I cannot get it ot work with crontab.

I have run sudo chmod +x analyze.py as well as sudo chmod ugo+w analyze.py.

My whereis python3 says /usr/bin/python3. The shebang at the top of my analyze.py script is #!/usr/bin/python3.

My crontab script is * * * * * /usr/bin/python3 /home/projects/temperature_logger/analyze.py

For testing purposes all I have actually running right now is

if __name__ == '__main__':
    logging.info("running file!")

in my analyze.py but I do not see this getting populated to my log file unless I manually call sudo python3 analyze.py from within the directory.

What am I doing wrong here? The syslogs don't seem to indicate anything wrong but perhaps I don't understand them? Apologies for the picture I am unsure how to copy from the PuTTy terminal enter image description here

Update: I added all permissions for my user ubuntu with sudo chmod -R a+rwx /home/projects/temperature_logger. I then changed the crontab, cleared out my root cron and put the call to the python script under ubuntu's cron file. I do see this reflected under the syslog now enter image description here

It does not seem to indicate any error. However, the script which when I call it with python3 analyze.py it does write properly to my scripts.log file, but when it's called from the cron, which it says is running the syslog - I don't see anything logged.

Solved: So this was due to me misunderstanding waht the home directory for my user account was and what the current working directory of the script was. In my analyze.py script I had logging.basicConfig(filename='scripts.log', ...), which when I ran from the directory with sudo, wrote to /home/projects/temperature_logger/scripts.log, but when it was called from my user's cron file, it wrote to /home/ubuntu/scripts.log.

added 632 characters in body
Source Link
bjk116
  • 121
  • 5

I have a script /home/projects/temperature_logger/analyze.py that does some work on a temp.log file, which is really a csv of a date and the current raspberry pi temperature. This python script also logs the results to a .log file. Calling it from the command line like sudo python3 analyze.py works as expected, but for some reason I cannot get it ot work with crontab.

I have run sudo chmod +x analyze.py as well as sudo chmod ugo+w analyze.py.

My whereis python3 says /usr/bin/python3. The shebang at the top of my analyze.py script is #!/usr/bin/python3.

My crontab script is * * * * * /usr/bin/python3 /home/projects/temperature_logger/analyze.py

For testing purposes all I have actually running right now is

if __name__ == '__main__':
    logging.info("running file!")

in my analyze.py but I do not see this getting populated to my log file unless I manually call sudo python3 analyze.py from within the directory.

What am I doing wrong here? The syslogs don't seem to indicate anything wrong but perhaps I don't understand them? Apologies for the picture I am unsure how to copy from the PuTTy terminal enter image description here

Update: I added all permissions for my user ubuntu with sudo chmod -R a+rwx /home/projects/temperature_logger. I then changed the crontab, cleared out my root cron and put the call to the python script under ubuntu's cron file. I do see this reflected under the syslog now enter image description here

It does not seem to indicate any error. However, the script which when I call it with python3 analyze.py it does write properly to my scripts.log file, but when it's called from the cron, which it says is running the syslog - I don't see anything logged.

I have a script /home/projects/temperature_logger/analyze.py that does some work on a temp.log file, which is really a csv of a date and the current raspberry pi temperature. This python script also logs the results to a .log file. Calling it from the command line like sudo python3 analyze.py works as expected, but for some reason I cannot get it ot work with crontab.

I have run sudo chmod +x analyze.py as well as sudo chmod ugo+w analyze.py.

My whereis python3 says /usr/bin/python3. The shebang at the top of my analyze.py script is #!/usr/bin/python3.

My crontab script is * * * * * /usr/bin/python3 /home/projects/temperature_logger/analyze.py

For testing purposes all I have actually running right now is

if __name__ == '__main__':
    logging.info("running file!")

in my analyze.py but I do not see this getting populated to my log file unless I manually call sudo python3 analyze.py from within the directory.

What am I doing wrong here? The syslogs don't seem to indicate anything wrong but perhaps I don't understand them? Apologies for the picture I am unsure how to copy from the PuTTy terminal enter image description here

I have a script /home/projects/temperature_logger/analyze.py that does some work on a temp.log file, which is really a csv of a date and the current raspberry pi temperature. This python script also logs the results to a .log file. Calling it from the command line like sudo python3 analyze.py works as expected, but for some reason I cannot get it ot work with crontab.

I have run sudo chmod +x analyze.py as well as sudo chmod ugo+w analyze.py.

My whereis python3 says /usr/bin/python3. The shebang at the top of my analyze.py script is #!/usr/bin/python3.

My crontab script is * * * * * /usr/bin/python3 /home/projects/temperature_logger/analyze.py

For testing purposes all I have actually running right now is

if __name__ == '__main__':
    logging.info("running file!")

in my analyze.py but I do not see this getting populated to my log file unless I manually call sudo python3 analyze.py from within the directory.

What am I doing wrong here? The syslogs don't seem to indicate anything wrong but perhaps I don't understand them? Apologies for the picture I am unsure how to copy from the PuTTy terminal enter image description here

Update: I added all permissions for my user ubuntu with sudo chmod -R a+rwx /home/projects/temperature_logger. I then changed the crontab, cleared out my root cron and put the call to the python script under ubuntu's cron file. I do see this reflected under the syslog now enter image description here

It does not seem to indicate any error. However, the script which when I call it with python3 analyze.py it does write properly to my scripts.log file, but when it's called from the cron, which it says is running the syslog - I don't see anything logged.

Source Link
bjk116
  • 121
  • 5

Issue running python script from crontab?

I have a script /home/projects/temperature_logger/analyze.py that does some work on a temp.log file, which is really a csv of a date and the current raspberry pi temperature. This python script also logs the results to a .log file. Calling it from the command line like sudo python3 analyze.py works as expected, but for some reason I cannot get it ot work with crontab.

I have run sudo chmod +x analyze.py as well as sudo chmod ugo+w analyze.py.

My whereis python3 says /usr/bin/python3. The shebang at the top of my analyze.py script is #!/usr/bin/python3.

My crontab script is * * * * * /usr/bin/python3 /home/projects/temperature_logger/analyze.py

For testing purposes all I have actually running right now is

if __name__ == '__main__':
    logging.info("running file!")

in my analyze.py but I do not see this getting populated to my log file unless I manually call sudo python3 analyze.py from within the directory.

What am I doing wrong here? The syslogs don't seem to indicate anything wrong but perhaps I don't understand them? Apologies for the picture I am unsure how to copy from the PuTTy terminal enter image description here