1

I am running a python script on a Linux EC2 instance (the standard AMI) and I am having trouble executing a python script through the Crontab. I have another cron job already running and followed the same format. I think I'm missing something simple, but have had trouble identifying the cause. Here is what pops up when I run crontab -e

*/5 * * * * ~/scripts/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron
*/1 * * * * ~/scripts/python cpu-util.py

The error I get in the logs is /bin/sh: /root/scripts/python: No such file or directory

I'm a little confused about this error message because the path from when I log in is ~/scripts, which has my Python script.

I also tried */1 * * * * ~/scripts python cpu-util.py (which I thought made more sense), but rearranged my code based on this other post to no avail.

Also, does it matter if I run these tasks from root or ec2-user? I just put the same scripts in both to be safe (sorry if this is two questions in one, but just curious about this...)

Any input would be great. Thanks!

Rob Z
  • 81
  • 1
  • 8

1 Answers1

2

in your line you are looking for

the python application inside your scripts folder

I guess this is not what you intended. Try this out:

*/1 * * * * /usr/bin/python ~/scripts/cpu-util.py

I think this should work.

Also you can call it directly using ./ just putting inside your python script as the first line.

#!/usr/bin/env python

Then you can run it like this

*/1 * * * * /usr/bin/sh ~/scripts/cpu-util.py
Sebas
  • 324
  • 2
  • 10