0

To edit the root crontab in Debian I do for example sudo crontab -e. To exit from the preferred text editor (Nano), I do CTLR+X.

So far so good, but what if I want that each time I exit crontab, a text will be echoed into the console (into "stdout").

The purpose is to echo a reminder message like:

If you haven't already, change p to your password in password[p] to your password!

To make sure I'm clear here --- I desire that each time the user finished editing the crontab and then quited back to the console, the message will appear.

Is there any way to do so in the current release of Bash?

2 Answers 2

2

You can assign the $EDITOR variable a script which first calls an editor and then produces the output:

#! /bin/bash

vim "$1"
echo "foo bar baz"

and use this call

EDITOR=/path/to/script.sh crontab -e
1

there is a baf/ugly method for that .... Maybe someone have a better solution ... replace crontab binary by a script & rename original to somthing called crontab.original called by the script.

#!/bin/bash
crontab.original $1 #or all arguments if you wish to
echo YOUR MESSAGE
exit 0
6
  • Thx! What is $1? Commented Jan 4, 2018 at 19:46
  • 1st parameter $2 the second etc... in cas you wish to pass -l or -e options/args to crontab.original command
    – francois P
    Commented Jan 4, 2018 at 19:49
  • Oh I see, like domain for ${domain} and then example1.com, example2.com and so forth, as execution arguments. Commented Jan 4, 2018 at 19:57
  • 1
    @francoisP Shell functions don‘t work together with sudo :-)
    – nohillside
    Commented Jan 4, 2018 at 20:04
  • 1
    Really ought to be crontab.original "$@" to be the least surprising behavior.
    – derobert
    Commented Jan 4, 2018 at 20:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .