How to make crontab run a script in Python

2

I'm trying to schedule a script I wrote in Python to run in crontab , but I'm not able to do it. The script is simple thing, it makes a telnet connection through the terminal and sends some commands. I was able to schedule a shellscript , however I am not able to schedule the Python script.

I tried to schedule the following in the crontab:

* * * * * /root/pasta/script.py
* * * * * /root/pasta/script.py > /dev/tty1
* * * * * /usr/bin/python /root/pasta/script.py
* * * * * /usr/bin/python /root/pasta/script.py > /dev/tty1

I put it at the beginning of the script #!/usr/bin/python and it was not.

The script works normally on the terminal, it just does not work in the crontab schedule.

Python is the standard for Ubuntu, version 2.7.6.

Follow the Python code:

#!/usr/bin/python
import os;

# Conecta no servidor telnet e envia uma mensagem.
# O servidor responde com um 'ok'.
os.system("""
(echo 'teste';
sleep 1;
echo 'quit';
exit) | telnet localhost 23""");
    
asked by anonymous 09.03.2018 / 02:46

1 answer

1

I managed to make it work ... Actually I do not know what the problem was, but after restarting the whole system it started to work fine. If it works for someone, my crontab looks like this:

* * * * * /usr/bin/python /root/pasta/script.py

Thanks guys!

    
09.03.2018 / 17:32