home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / utils / crontab.el < prev    next >
Encoding:
Text File  |  1995-04-17  |  4.9 KB  |  144 lines

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