Managing cron.d with chef

I have recently been playing with the chef configuration management system. I was looking for a way to manage files in a directory such that any that were created by chef would be cleaned up again when they were no longer needed. A classic use case is the /etc/cron.d directory which may be populated by files from multiple sources. There appeared to be no established pattern for this but since chef allows the use of ruby in its recipes, I was able to construct the following. It assumes the use of the cron cookbook.

[code language=”ruby”]
cron_d ‘usercron.chef’ do
minute 0
hour 23
command ‘/bin/true’
user ‘myuser’
end

Dir.glob("/etc/cron.d/*.chef") do |f|
name = f.split(‘/’)[-1]
begin
t = resources("cron_d[#{name}]")
rescue Chef::Exceptions::ResourceNotFound
cron_d name do
action :delete
end
end
end
[/code]

OS X Terminal.app, bash and UK Keyboards

On an Apple UK keyboard, the # symbol is accessed by pressing ⌥-3 (pronounced option 3). Unfortunately the terminal application is only useable when option has been mapped to the UNIX meta-key, which takes precedence over “special” characters such as #. Thanks to this tumblr post, it is possible to work around this problem:

$ cat .inputrc
"\e3": "#"

Unfortunately .inputrc is a bash-specific configuration file and this does not solve the problem for terminal-based applications.