1 ;; #(@) crontab.el - An Emacs function to assist in editing crontab entries
2 ;; Last edited: Fri Aug 18 12:19:22 1989 by chris (Christopher D. Orr) on lxn
4 ;; Version: 1.00 - Initial Creation of mode
5 ;; 1.01 - Added crontab-use-local-file variable
6 ;; 1.02 - Reworked most of the library to be cleaner.
7 ;; 1.03 - Now deletes blank lines in crontab entry
9 ;; Copyright (C) 1989 Christopher D. Orr (chris@lxn.eds.com)
11 ;; This file is part of XEmacs.
13 ;; XEmacs is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; XEmacs is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
28 ;;; Synched up with: Not in FSF.
34 ;; Place the following line in your ~/.emacs file:
35 ;; (autoload 'crontab-edit "crontab"
36 ;; "Function to allow the easy editing of crontab files." t)
39 (provide 'crontab-edit)
41 ;;; Local Variables. Define these to your liking.
44 "Assist in editing crontab files."
48 (defcustom crontab-filename "~/.crontab"
49 "*The name of the file to store the User's Crontab."
53 (defcustom crontab-directory "/usr/spool/cron/crontabs"
54 "*The name of the directory in which crontab stores it's entries."
58 (defcustom crontab-use-local-file nil
59 "*Non-nil means use file stored in User's Home directory, if it exists.
60 Otherwise, always ask crontab for the current entry (maybe)."
64 (defcustom crontab-delete-blank-lines t
65 "*Non-nil means to delete any blank lines in the crontab file on save."
69 ;;; Interactive Function called to edit a Crontab Entry. It is called
70 ;;; instead of crontab-edit to allow for future automatic entries.
72 (defun crontab-edit ()
73 "Function to allow the easy editing of crontab files."
79 ;;; Function to retrieve the crontab entry. The Function will
80 ;;; retrieve the file (crontab-filename) first. If the file does not
81 ;;; exists, a crontab -l command will be executed.
84 "Retrieve a crontab file either using crontab -l or from the variable
86 (message "Retrieving Crontab ... ")
87 (switch-to-buffer (create-file-buffer crontab-filename))
90 (if (file-exists-p crontab-filename)
91 (if (file-newer-than-file-p (concat crontab-directory "/" (user-login-name)) (expand-file-name crontab-filename))
92 (if (yes-or-no-p "Cron has a more recent copy of your crontab. Use it ? ")
93 (call-process "crontab" nil t t "-l")
94 (insert-file crontab-filename))
95 (if crontab-use-local-file
96 (insert-file crontab-filename)
97 (call-process "crontab" nil t t "-l")))
98 (if crontab-use-local-file
99 (insert-file crontab-filename)
100 (call-process "crontab" nil t t "-l")))
102 ;; What if crontab returns a fatal ?????? Can't we check the errorlevel ????
103 (goto-char (point-min))
104 (if (search-forward-regexp "crontab:\\|no crontab for" nil t nil)
107 (crontab-initialize))
109 (setq buffer-file-name crontab-filename)
110 (set-buffer-modified-p nil)
111 (make-variable-buffer-local 'write-file-hooks)
112 (or (memq 'crontab-save write-file-hooks)
113 (setq write-file-hooks
114 (reverse (cons 'crontab-save (reverse write-file-hooks)))))
115 (message "Save file normally when finished to update cron."))
118 ;;; This function is called whenever a save-file operation is
119 ;;; performed in the crontab buffer. It saves the crontab to the file
120 ;;; name (crontab-filename) and then removes the crontab buffer.
122 (defun crontab-save ()
123 "Submit the edited crontab to the cron daemon for processing."
125 (when crontab-delete-blank-lines
126 (goto-char (point-min))
132 (setq write-file-hooks nil)
133 (let ((crontab-buffer (buffer-name)))
136 ;; What if the call-process to crontab fails ??? Can we check for a fatal ???
137 ;; (call-process "crontab" nil nil nil (expand-file-name crontab-filename))
138 (shell-command (concat "crontab " (expand-file-name crontab-filename)))
140 (switch-to-buffer (other-buffer))
141 (kill-buffer crontab-buffer))
142 (message (concat "Crontab saved as " crontab-filename " and submitted to cron."))
143 ;; fixed by Lynn D. Newton - 03/17/95
148 (defun crontab-initialize ()
149 "Create a default Crontab file if one does not exist or is empty.
150 If the function (time-stamp) is available, the last modification time will
151 be stamped to the file."
153 (insert "# Cron Table Entry for ")
154 (insert (user-login-name))
156 (insert (user-full-name))
157 (insert ")\n# Last Edited: \n")
159 (insert "# min hr day mon wday(0=sun) cmd\n")
162 ;;; Watch out for the signature :-)