简体   繁体   中英

having problems using python script in linux crontab

having problems using python script in linux crontab. I'm trying to run the Wal logs postgresql cleanup script, but I'm facing a problem such that there is no tty terminal in crontab. as a result I get an error in the logs.



nameContainer = "postgres"

cmdGrep = f'docker exec -it {nameContainer}  /usr/lib/postgresql/10/bin/pg_controldata /var/lib/postgresql/10/main/ | grep REDO'
res = os.popen (cmdGrep).read()
resFilter = res.rsplit(':')
cmdGo = f'docker exec -it {nameContainer} pg_archivecleanup -d /var/lib/postgresql/10/archive {resFilter[2].strip()} '
os.system(cmdGo)


error:
the input device is not a TTY
Traceback (most recent call last):
  File "/srv/scripts/clearWalLogs.py", line 9, in <module>
    cmdGo = f'docker exec -it {nameContainer} pg_archivecleanup -d /var/lib/postgresql/10/archive {resFilter[2].strip()} '
IndexError: list index out of range```


The problem is caused by the use of a pseudo-TTY for input from STDIN , which is invoked by the option -t during docker exec .
As the commands revoked by docker exec doesn't need any user input, the option -it can be omitted from docker exec and therefore the process executed without a error message.

STDOUT will still be captured, even without the use of -it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM