0

I am trying to list cronjobs of all users

user_file = open('/root/pys/userdomains', 'r')
for line in user_file:
    print line
    splitted_line = line.split(': ')
    print splitted_line
    user_cron = splitted_line[1].split()[0]
    print user_cron
    print "crons for", user_cron, "is", CronTab(user=user_cron)

On last line, can I use

os.system('crontab -l -u user_cron')

to get similar result? I know there is CronTab option, but in similar cases, can I use python variables (e.g. user_cron) inside bash commands.

Prune
  • 76,765
  • 14
  • 60
  • 81
chiju
  • 27
  • 2
  • 6

2 Answers2

1

Not quite: you need to construct the actual command string you want to use: Append the string value of user_cron to the literal part of the command.

os.system('crontab -l -u ' + user_cron)
Prune
  • 76,765
  • 14
  • 60
  • 81
0

Yes you can use os.system function, but you must import os.

import os
os.system('crontab -l -u user_cron')
tripleee
  • 175,061
  • 34
  • 275
  • 318