old crontab entries not removed

Bug #664783 reported by Richard de Boer
32
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Back In Time
Fix Released
Critical
Unassigned

Bug Description

On saving the preferences, backintime creates a new crontab entry, but fails to remove the old one.

From bug 451811 I figured it might be useful to paste this output as well(this was after manual removal of the duplicate entry, I copied this regex from config.py):

richard@bagheera:~$ crontab -l | grep -Pv '(?s)#Back In Time system entry, this will be edited by the gui:.*?backintime'
#Fetch mail from Ziggo POP server to local storage
*/5 * * * * /usr/bin/getmail >/dev/null 2>&1
#Back In Time system entry, this will be edited by the gui:
0 * * * * nice -n 19 ionice -c2 -n7 /usr/bin/backintime --profile "Main profile" --backup-job >/dev/null 2>&1

Looks like even with the -P option and (?s) grep doesn't find the Backintime lines. I also tried it without the ? in front of backintime, as it looked wrong to me(I might be mistaken there), but got the same result.
Removing the last part did result in grep removing the comment line:

richard@bagheera:~$ crontab -l | grep -Pv '(?s)#Back In Time system entry, this will be edited by the gui:.*?'
#Fetch mail from Ziggo POP server to local storage
*/5 * * * * /usr/bin/getmail >/dev/null 2>&1
0 * * * * nice -n 19 ionice -c2 -n7 /usr/bin/backintime --profile "Main profile" --backup-job >/dev/null 2>&1

Using:
Back in Time 1.0
GNU grep 2.6.3
Python 2.6.6
Linux bagheera 2.6.35-22-generic #35-Ubuntu SMP Sat Oct 16 20:36:48 UTC 2010 i686 GNU/Linux

Revision history for this message
Richard de Boer (rich-home-deactivatedaccount) wrote :
Revision history for this message
Dan (danleweb) wrote :

This seems tp be related to Ubuntu 10.10.

Changed in backintime:
status: New → Confirmed
importance: Undecided → Critical
Dan (danleweb)
Changed in backintime:
status: Confirmed → Fix Committed
Dan (danleweb)
Changed in backintime:
status: Fix Committed → Fix Released
Revision history for this message
Michele (mikelito) wrote :

Sorry ,but the fix you had just submitted does not work on my system (1.0.2 @ Maverick) either.
I might be wrong, but grep is just not able to catch a pattern across multiple lines.

I am currently using
os.system( "crontab -l | sed -e '/%s/,+1d' | crontab -" % system_entry_message )
which does the job just fine.

Clearly it has the problem that it would remove the line following system_entry_message regardless of its content, which is maybe bad.
I'll play a bit with sed to see if I can find something completely equivalent to grep but more robust.

Thanks for looking into this!

Revision history for this message
Richard de Boer (rich-home-deactivatedaccount) wrote :

How about using awk instead of grep to remove the lines? the grep manpage also warns that using -P is experimental, so it would be likely to break on more systems anyway.

This awk script should work:

'/#Back In Time system entry, this will be edited by the gui:/ {skip=1} /.*/ {if (!skip) print $0} /.*backintime.*/ {skip=0}'

-It first checks for the BackInTime comment, if it is present it starts skipping lines
-If it's not skipping lines it prints the current line
-If the current line contains "backintime" it stops skipping lines

Example output:

richard@bagheera:~$ crontab -l
#Fetch mail from Ziggo POP server to local storage
*/5 * * * * /usr/bin/getmail >/dev/null 2>&1
#Back In Time system entry, this will be edited by the gui:
0 * * * * nice -n 19 ionice -c2 -n7 /usr/bin/backintime --profile "Main profile" --backup-job >/dev/null 2>&1
#test123
richard@bagheera:~$ crontab -l | awk '/#Back In Time system entry, this will be edited by the gui:/ {skip=1} /.*/ {if (!skip) print $0} /.*backintime.*/ {skip=0}'
#Fetch mail from Ziggo POP server to local storage
*/5 * * * * /usr/bin/getmail >/dev/null 2>&1
#test123

Line 741 in config.py would change from
  os.system( "crontab -l | grep -Pv '(?s)%s.*?backintime' | crontab -" % system_entry_message )
to
  os.system( "crontab -l | awk '/%s/ {skip=1} /.*/ {if (!skip) print $0} /.*backintime.*/ {skip=0}' | crontab -" % system_entry_message )

Revision history for this message
Jan Schnackenberg (yehaa) wrote :

I've just noticed the same problem.

BackInTime Version 0.9.99.80
Using KDE Development Platform 4.5.85 (4.6 Beta2)

Kubuntu 10.10

The awk line posted by Richard de Boer works wonderfully, so I'd give that a +, I'm not fluent enough in shell-scripting to analyze that line in depth.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.