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\"; } }

In reply to safe cron by mincus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.