annotate lisp/utils/crontab.el @ 69:804d1389bcd6

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