Having set a lecture with Default lecture=always and Default lecture_file=/etc/sudoers.lecture, I would like to add colour to it. ANSI escape characters show without escaping, and creating a wrapper function displays it every time I use sudo, even if the password is in the cache.
Asked
Active
Viewed 354 times
2
Jeff Schaller
- 66,199
- 35
- 114
- 250
gadzooks02
- 141
- 4
-
1What is a `lecture`? – k.stm Aug 23 '19 at 17:05
-
@k.stm This is described in the `sudoers(5)` manual. It is the short text that is outputted upon first using `sudo`, which (by default) reminds the user to use the command responsibly. – Kusalananda Aug 23 '19 at 17:22
-
Cannot reproduce here; using the appropriate [`tput`](https://unix.stackexchange.com/a/241450/117549) output, I created a file that sudo dutifully outputted in color. How did you produce the /etc/sudoers.lecture file? – Jeff Schaller Aug 23 '19 at 18:38
-
Related: https://unix.stackexchange.com/q/9957/117549 – Jeff Schaller Aug 23 '19 at 18:39
-
@JeffSchaller, I also don't know how `tput` works. – gadzooks02 Aug 25 '19 at 18:28
-
@JeffSchaller, I do (now) know how `tput` works, but I cannot get it to display colour when put in sudoers,lecture. – gadzooks02 Aug 27 '19 at 18:00
-
@gadzooks02: are you displaying the lecture in the same type of terminal as you generate the colors in? The value of `$TERM` is the critical piece, I think. – Jeff Schaller Aug 27 '19 at 18:13
-
@JeffSchaller what do you mean by 'generating' the colours? – gadzooks02 Aug 27 '19 at 18:15
-
I imagine you'd use `tput` to generate the colored text? – Jeff Schaller Aug 27 '19 at 18:15
-
If by 'generate', you mean adding `$(tput setaf
)` to sudoers.lecture, then yes – gadzooks02 Aug 27 '19 at 18:21 -
@JeffSchaller NVM, I found what you mean: `echo $(tput setaf
) – gadzooks02 Aug 27 '19 at 19:32>> /etc/sudoers.lecture`
1 Answers
2
Using:
echo $(tput setaf <colour>)<text>$(tput sgr0) >> /etc/sudoers.lecture
adds coloured text to /etc/sudoers.lecture
gadzooks02
- 141
- 4