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