Search code examples
pythoncronraspberry-pi3nano

How to save crontab -e on nano editor by python3 subprocess


I want to set cronjob on Raspberry Pi 3, initiated by python subprocess, but I am not sure how to code pressing keys ctrl + x ,then y ,and then enter to save it. I am using nano as a text editor, and the below is my code so far.

p = Popen(["crontab -e"], stdin=PIPE, stdout=PIPE, shell=True)
p.stdin.write("@reboot python test.py")

Solution

  • you can do it with the following bash command without using vi editor:

    (crontab -l ; echo "0 4 * * * myscript")| crontab -