Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

old crontab entries not removed #3

Closed
Germar opened this issue Oct 11, 2015 · 5 comments
Closed

old crontab entries not removed #3

Germar opened this issue Oct 11, 2015 · 5 comments

Comments

@Germar
Copy link
Member

Germar commented Oct 11, 2015

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


Imported from Launchpad using lp2gh.

@Germar
Copy link
Member Author

Germar commented Oct 11, 2015

(by rich-home-deactivatedaccount)

@Germar
Copy link
Member Author

Germar commented Oct 11, 2015

(by danleweb)
This seems tp be related to Ubuntu 10.10.

@Germar
Copy link
Member Author

Germar commented Oct 11, 2015

(by mikelito)
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!

@Germar
Copy link
Member Author

Germar commented Oct 11, 2015

(by rich-home-deactivatedaccount)
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 )

@Germar
Copy link
Member Author

Germar commented Oct 11, 2015

(by yehaa)
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant