Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

safe cron

by mincus (Chaplain)
on Jun 14, 2005 at 13:56 UTC ( [id://466539]=CUFP: print w/replies, xml ) Need Help??

After having my crontab deleted for the 3rd time from "fat fingering" -r instead of -e(they're so close!), I created this little script that adds a prompt to delete the crontab.

1) Create /usr/local/scripts/safe_crontab.pl with the code below.
2) Add this line to /etc/bashrc (or your personal .bashrc) alias crontab='/usr/local/scripts/safe_crontab.pl'
3) Run the following command: chmod 755 /usr/local/scripts/safe_crontab.pl
4) Log off and back on and you should be all set. Hope you find this useful.
#!/usr/bin/perl -w use strict; my $run_crontab = 1; my @safe_argv; my ( $bForce, $bRemove, $bHelp ); foreach ( @ARGV ) { if ( uc( $_ ) eq '--FORCE' ) { $bForce = 1; } else { if ( uc( $_ ) eq '-R' ) { $bRemove = 1; } push( @safe_argv, $_ ); } } if ( $bRemove ) { unless( $bForce ) { my ( $y_or_n ); do { print 'Are you sure you want to remove the crontab? (Y/N): + '; $y_or_n = uc( getc() ); print \"\n\"; } until ( ( $y_or_n eq 'Y' ) || ( $y_or_n eq 'N' ) ); if ( $y_or_n eq 'N' ) { print \"/usr/bin/crontab: no changes made to crontab\n\"; $run_crontab = 0; } } } if ( $run_crontab ) { if ( system( '/usr/bin/crontab', @safe_argv ) == 256 ) { print \"\t--force (delete crontab without prompting)\n\"; } }

Replies are listed 'Best First'.
Re: safe cron
by davidrw (Prior) on Jun 14, 2005 at 14:08 UTC
    yes, that is EVIL that -e and -r are next to each other on the keyboard and -r doesn't confirm. I have conditioned my self to put a 2-second pause before hitting ENTER after typing "crontab -X" to make sure i did 'e' and not 'r'.

    My more robust (than double-checking my typing) solution was to add these two cron entries:
    0 1 * * * /usr/bin/crontab -l > /home/myname/archive/backup/crontab/dr +w.cron 0 5 * * * /usr/sbin/logrotate --state /home/myname/.logrotate.status / +home/myname/.logrotate
    And this ~/.logrotate entry (i actually have a bunch of other stuff in there too):
    /home/myname/archive/backup/crontab/drw.cron { rotate 28 daily compress }
      I did also start backing up the crontab in my daily backup... it was just one of those frustrating, "why didnt they see this problem... must fix" impulses that seems to take over your brain as a perl hacker.
      that is EVIL that -e and -r are next to each other

      Having the d and the f next to each other is not any better...

      Quick, f*ck!

Re: safe cron
by kelan (Deacon) on Jun 15, 2005 at 13:13 UTC

    Another solution, albeit one that involves a bit more work, is to switch to the Dvorak keyboard layout. 'e' and 'r' are no where near each other; in fact, they're typed by different hands. Plus, your wrists and fingers will thank you.

    Please note that this post is mostly in jest. I realize that learning a new keyboard layout merely to prevent goofing up the 'e' and 'r' keys would be a bit silly. However, I do find typing much nicer with Dvorak than I did with Qwerty. Just ask Juerd about it:)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://466539]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-19 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found