1

When I use

sudo -u tango crontab -l >> /tmp/crontango.txt

within the terminal it works fine.

Doing the following in python

import subprocess

subprocess.run(['sudo', '-u tango', 'crontab', '-l', '>>', '/tmp/crontango.txt'])

leads to an error

sudo: unknown user: tango

I tried to reconfigure the arguments without any success.

How do I copy my crontab to a textfile using a python script?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
tangomike
  • 13
  • 3

1 Answers1

1

You should separate all arguments and catch the output like so:

with open('/tmp/crontango.txt', 'a') as f:
    subprocess.run(['sudo', '-u', 'tango', 'crontab', '-l'], stdout=f)
MiaPlan.de
  • 102
  • 8