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""");