Python - Split crontab entry to 6 fields
<p>I would like to know how to split a crontab line into 6 variables like the following. Maybe with split() or other string functions.</p>

<pre><code>Input:
0 5 * * * Command1 arg1 arg2;Command2 arg1 arg2;...

Output:
Var1 = 0
Var2 = 5 
Var3 = * 
Var4 = *
Vat5 = Command1 arg1 arg 2;Command 2 arg1 arg2...
</code></pre>

<p>Thanks</p>

<p><a href="https://docs.python.org/3.6/library/stdtypes.html#str.split" rel="nofollow"><code>str.split()</code></a> has an optional 2nd argument to limit the number of returned values:</p>

<pre><code>In [11]: s='0 5 * * * Command1 arg1 arg2;Command2 arg1 arg2;...'

In [12]: s.split(None, 5)
Out[12]: ['0', '5', '*', '*', '*', 'Command1 arg1 arg2;Command2 arg1 arg2;...']
</code></pre>

<p>Complete sample program:</p>

<pre><code>import fileinput

for line in fileinput.input():
    parts = line.split(None, 5)
    print('Input:')
    print(line)
    print('Output:')
    print('\n'.join('Var{} = {}'.format(i, v) for i,v in enumerate(parts)))
</code></pre>

python split crontab