def action_delete
if @cron_exists
crontab = String.new
cron_found = false
status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
stdout.each_line do |line|
case line.chomp
when "# Chef Name: #{@new_resource.name}"
cron_found = true
next
when CRON_PATTERN
if cron_found
cron_found = false
next
end
else
next if cron_found
end
crontab << line
end
end
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
crontab.each_line { |line| stdin.puts "#{line}" }
end
Chef::Log.info("#{@new_resource} deleted crontab entry")
@new_resource.updated_by_last_action(true)
end
end