annotate lisp/utils/crontab.el @ 14:9ee227acff29 r19-15b90

Import from CVS: tag r19-15b90
author cvs
date Mon, 13 Aug 2007 08:48:42 +0200
parents 376386a54a3c
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; #(@) crontab.el - An Emacs function to assist in editing crontab entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Last edited: Fri Aug 18 12:19:22 1989 by chris (Christopher D. Orr) on lxn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Version: 1.00 - Initial Creation of mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; 1.01 - Added crontab-use-local-file variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; 1.02 - Reworked most of the library to be cleaner.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; 1.03 - Now deletes blank lines in crontab entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Copyright (C) 1989 Christopher D. Orr (chris@lxn.eds.com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; TODO:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; Place the following line in your ~/.emacs file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; (autoload 'crontab-edit "crontab"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; "Function to allow the easy editing of crontab files." t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (provide 'crontab-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; Local Variables. Define these to your liking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defvar crontab-filename "~/.crontab"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 "*The name of the file to store the User's Crontab.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defvar crontab-directory "/usr/spool/cron/crontabs"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 "*The name of the directory in which crontab stores it's entries.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (defvar crontab-use-local-file nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 "*Non-nil means use file stored in User's Home directory, if it exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 Otherwise, always ask crontab for the current entry (maybe).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; Interactive Function called to edit a Crontab Entry. It is called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; instead of crontab-edit to allow for future automatic entries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defun crontab-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "Function to allow the easy editing of crontab files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (crontab-get))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; Function to retrieve the crontab entry. The Function will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; retrieve the file (crontab-filename) first. If the file does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; exists, a crontab -l command will be executed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (defun crontab-get ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 "Retrieve a crontab file either using crontab -l or from the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 crontab-filename"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (message "Retrieving Crontab ... ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (switch-to-buffer (create-file-buffer crontab-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (if (file-exists-p crontab-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (if (file-newer-than-file-p (concat crontab-directory "/" (user-login-name)) (expand-file-name crontab-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (if (yes-or-no-p "Cron has a more recent copy of your crontab. Use it ? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (call-process "crontab" nil t t "-l")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (insert-file crontab-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if crontab-use-local-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (insert-file crontab-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (call-process "crontab" nil t t "-l")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (if crontab-use-local-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (insert-file crontab-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (call-process "crontab" nil t t "-l")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; What if crontab returns a fatal ?????? Can't we check the errorlevel ????
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (if (search-forward "crontab:" nil t nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (erase-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (crontab-initialize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (goto-line 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (setq buffer-file-name crontab-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (make-variable-buffer-local 'write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (or (memq 'crontab-save write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq write-file-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (reverse (cons 'crontab-save (reverse write-file-hooks)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (message "Save file normally when finished to update cron."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;; This function is called whenever a save-file operation is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;; performed in the crontab buffer. It saves the crontab to the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;; name (crontab-filename) and then removes the crontab buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defun crontab-save ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "Submit the edited crontab to the cron deamon for processing"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (delete-blank-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (redraw-display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (setq write-file-hooks nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (let ((crontab-buffer (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (basic-save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; What if the call-process to crontab fails ??? Can we check for a fatal ???
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; (call-process "crontab" nil nil nil (expand-file-name crontab-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (shell-command (concat "crontab " (expand-file-name crontab-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (switch-to-buffer (other-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (kill-buffer crontab-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (message (concat "Crontab saved as " crontab-filename " and submitted to cron."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; fixed by Lynn D. Newton - 03/17/95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; OLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defun crontab-initialize ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 "Create a default Crontab file if one does not exist or is empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 If the function (time-stamp) is available, the last modification time will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 be stamped to the file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (insert "# Cron Table Entry for ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (insert (user-login-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (insert " (")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (insert (user-full-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (insert ")\n# Last Edited: \n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (insert "#\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (insert "# min hr day mon wday(0=sun) cmd\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (insert "#\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;;; Watch out for the signature :-)