0
|
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
|
|
3 ;;
|
|
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
|
|
8
|
|
9 ;; Copyright (C) 1989 Christopher D. Orr (chris@lxn.eds.com)
|
|
10
|
|
11 ;; This file is part of XEmacs.
|
|
12
|
|
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)
|
|
16 ;; any later version.
|
|
17
|
|
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.
|
|
22
|
|
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 Free
|
|
25 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
26
|
|
27 ;;; Synched up with: Not in FSF.
|
|
28
|
|
29 ;;
|
|
30 ;; TODO:
|
|
31 ;;
|
|
32
|
|
33 ;; Place the following line in your ~/.emacs file:
|
|
34 ;; (autoload 'crontab-edit "crontab"
|
|
35 ;; "Function to allow the easy editing of crontab files." t)
|
|
36 ;;
|
|
37
|
|
38 (provide 'crontab-edit)
|
|
39
|
|
40 ;;; Local Variables. Define these to your liking.
|
|
41
|
|
42 (defvar crontab-filename "~/.crontab"
|
|
43 "*The name of the file to store the User's Crontab.")
|
|
44
|
|
45 (defvar crontab-directory "/usr/spool/cron/crontabs"
|
|
46 "*The name of the directory in which crontab stores it's entries.")
|
|
47
|
|
48 (defvar crontab-use-local-file nil
|
|
49 "*Non-nil means use file stored in User's Home directory, if it exists.
|
|
50 Otherwise, always ask crontab for the current entry (maybe).")
|
|
51
|
|
52
|
|
53 ;;; Interactive Function called to edit a Crontab Entry. It is called
|
|
54 ;;; instead of crontab-edit to allow for future automatic entries.
|
|
55
|
|
56 (defun crontab-edit ()
|
|
57 "Function to allow the easy editing of crontab files."
|
|
58
|
|
59 (interactive)
|
|
60 (crontab-get))
|
|
61
|
|
62
|
|
63 ;;; Function to retrieve the crontab entry. The Function will
|
|
64 ;;; retrieve the file (crontab-filename) first. If the file does not
|
|
65 ;;; exists, a crontab -l command will be executed.
|
|
66
|
|
67 (defun crontab-get ()
|
|
68 "Retrieve a crontab file either using crontab -l or from the variable
|
|
69 crontab-filename"
|
|
70 (message "Retrieving Crontab ... ")
|
|
71 (switch-to-buffer (create-file-buffer crontab-filename))
|
|
72 (erase-buffer)
|
|
73
|
|
74 (if (file-exists-p crontab-filename)
|
|
75 (if (file-newer-than-file-p (concat crontab-directory "/" (user-login-name)) (expand-file-name crontab-filename))
|
|
76 (if (yes-or-no-p "Cron has a more recent copy of your crontab. Use it ? ")
|
|
77 (call-process "crontab" nil t t "-l")
|
|
78 (insert-file crontab-filename))
|
|
79 (if crontab-use-local-file
|
|
80 (insert-file crontab-filename)
|
|
81 (call-process "crontab" nil t t "-l")))
|
|
82 (if crontab-use-local-file
|
|
83 (insert-file crontab-filename)
|
|
84 (call-process "crontab" nil t t "-l")))
|
|
85
|
|
86 ;; What if crontab returns a fatal ?????? Can't we check the errorlevel ????
|
|
87 (goto-char (point-min))
|
|
88 (if (search-forward "crontab:" nil t nil)
|
|
89 (erase-buffer))
|
|
90 (if (eobp)
|
|
91 (crontab-initialize))
|
|
92 (goto-line 6)
|
|
93 (setq buffer-file-name crontab-filename)
|
|
94 (set-buffer-modified-p nil)
|
|
95 (make-variable-buffer-local 'write-file-hooks)
|
|
96 (or (memq 'crontab-save write-file-hooks)
|
|
97 (setq write-file-hooks
|
|
98 (reverse (cons 'crontab-save (reverse write-file-hooks)))))
|
|
99 (message "Save file normally when finished to update cron."))
|
|
100
|
|
101
|
|
102 ;;; This function is called whenever a save-file operation is
|
|
103 ;;; performed in the crontab buffer. It saves the crontab to the file
|
|
104 ;;; name (crontab-filename) and then removes the crontab buffer.
|
|
105
|
|
106 (defun crontab-save ()
|
|
107 "Submit the edited crontab to the cron deamon for processing"
|
|
108
|
|
109 (goto-char (point-min))
|
|
110 (while (not (eobp))
|
|
111 (delete-blank-lines)
|
|
112 (forward-line 1))
|
|
113 (redraw-display)
|
|
114
|
|
115 (setq write-file-hooks nil)
|
|
116 (let ((crontab-buffer (buffer-name)))
|
|
117 (basic-save-buffer)
|
|
118
|
|
119 ;; What if the call-process to crontab fails ??? Can we check for a fatal ???
|
|
120 ;; (call-process "crontab" nil nil nil (expand-file-name crontab-filename))
|
|
121 (shell-command (concat "crontab " (expand-file-name crontab-filename)))
|
|
122
|
|
123 (switch-to-buffer (other-buffer))
|
|
124 (kill-buffer crontab-buffer))
|
|
125 (message (concat "Crontab saved as " crontab-filename " and submitted to cron."))
|
|
126 ;; fixed by Lynn D. Newton - 03/17/95
|
|
127 "")
|
|
128 ;; OLD
|
|
129 ;; nil)
|
|
130
|
|
131 (defun crontab-initialize ()
|
|
132 "Create a default Crontab file if one does not exist or is empty.
|
|
133 If the function (time-stamp) is available, the last modification time will
|
|
134 be stamped to the file."
|
|
135
|
|
136 (insert "# Cron Table Entry for ")
|
|
137 (insert (user-login-name))
|
|
138 (insert " (")
|
|
139 (insert (user-full-name))
|
|
140 (insert ")\n# Last Edited: \n")
|
|
141 (insert "#\n")
|
|
142 (insert "# min hr day mon wday(0=sun) cmd\n")
|
|
143 (insert "#\n"))
|
|
144
|
|
145 ;;; Watch out for the signature :-)
|