3
I’m trying to schedule a script I wrote in Python to run on crontab, But I can’t do it. The script is simple thing, it makes a telnet connection through the terminal and sends some commands. I managed to schedule one shellscript, but I am unable to schedule the Python script.
I tried to schedule the following in 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 also was not.
Script works normally on the terminal, just doesn’t want to work on crontab scheduling.
Python is the default 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""");
Check the file permissions.
– Valdeir Psr
Try to make the file executable:
chmod +x /root/pasta/script.py
– Pedro von Hertwig Batista
The script is with permission 777, I put the folder also with 777 and continues in the same problem, the terminal runs smoothly in ". /script.py", but crontab does not.
– Gau