\input{gl2.slide-header-beamer}% \errorcontextlines=99 %% Subtopic Number = '1.111.4' %% Title from filename: 'Automate system administration tasks by scheduling jobs to run in the future' %% Weight: 4 %% Description: %% Candidate should be able to use cron or anacron to run jobs %% at regular intervals and to use at to run jobs at a specific time. Task %% include managing cron and at jobs and configuring user access to cron %% and at services. %% Key files, terms, and utilities include: %% /etc/anacrontab %% /etc/at.deny %% /etc/at.allow %% /etc/crontab %% /etc/cron.allow %% /etc/cron.deny %% /var/spool/cron/* %% at %% atq %% atrm %% crontab \title{1.111.4\\Automate system administration tasks by scheduling jobs to run in the future\\Weight 4}% \author[Angus Lees]{Angus Lees \texttt{} \and Geoff Robertson \texttt{} \and \and Nick Urbanik \texttt{}\\ {\tiny This document Licensed under GPL---see section~\ref{sec:license}}}% \subtitle{Linux Professional Institute Certification --- 102}% \mode
{\chead{1.111.4}}% % TODO Nick: % Fix this! Convert pstricks commands to pgf. % Temporary till have pgf documentation handy: \newcommand*{\rnode}[2]{#2} \newcommand*{\nccurve}[4]{} \begin{document} \maketitle \mode
{\thispagestyle{empty}} \begin{frame} \frametitle{Outline} \mode {% %\footnotesize \begin{multicols}{2} \tableofcontents \end{multicols} % You might wish to add the option [pausesections] }% \mode
{% \tableofcontents }% \end{frame} \section{Context} \label{sec:context} \begin{frame} \frametitle{Topic 111 Administrative Tasks [21]}% \framesubtitle{Where we are up to}% \begin{description} \item[1.111.1] Manage users and group accounts and related system files [4] \item[1.111.2] Tune the user environment and system environment variables [3] \item[1.111.3] Configure and use system log files to meet administrative and security needs [3] % \uline depends on \usepackage[normalem]{ulem}: \item[1.111.4] \textbf{\uline{Automate system administration tasks by scheduling jobs to run in the future [4]}} \item[1.111.5] Maintain an effective data backup strategy [3] \item[1.111.6] Maintain system time [4] \end{description} \end{frame} \section{Objective} \label{sec:objective} \begin{frame} %% GENERATED SLIDE \frametitle{Description of Objective}% \framesubtitle{1.111.4\ \ Automate system administration tasks by scheduling jobs to run in the future}% \mode{\Large}% Candidate should be able to use cron or anacron to run jobs at regular intervals and to use at to run jobs at a specific time. Task include managing cron and at jobs and configuring user access to cron and at services. \end{frame} % \begin{frame}[fragile] % %% GENERATED SLIDE % \frametitle{Key files, terms, and utilities include:} % \begin{semiverbatim}\large % /etc/anacrontab % /etc/at.deny % /etc/at.allow % /etc/crontab % /etc/cron.allow % /etc/cron.deny % /var/spool/cron/* % at % atq % atrm % crontab % \end{semiverbatim} % \end{frame} %============================================================================== \begin{frame}[fragile] \frametitle{111.4 Scheduling jobs [4]}% \framesubtitle{Key files, terms and utilities}% \mode{\large}% \begin{minipage}[t]{0.4\linewidth} \begin{description} \item \hyperlink{crontab}{\texttt{crontab}} \item \hyperlink{anacrontab}{\texttt{/etc/anacrontab}} \item \hyperlink{crontab}{\texttt{/etc/crontab}} \item \hyperlink{cron.allow}{\texttt{/etc/cron.allow}} \item \hyperlink{cron.deny}{\texttt{/etc/cron.deny}} \item \hyperlink{varspoolcron}{\texttt{/var/spool/cron/*}} \end{description} \end{minipage} % \begin{minipage}[t]{0.4\linewidth} \begin{description} \item \hyperlink{at}{\texttt{at}} \item \hyperlink{atq}{\texttt{atq}} \item \hyperlink{at.deny}{\texttt{/etc/at.deny}} \item \hyperlink{at.allow}{\texttt{/etc/at.allow}} \end{description} \end{minipage} \end{frame} %--------------------------------------- \section{Introduction} \label{sec:introduction} %============================================================================== %\pause %\overlays{7}{% \begin{frame}[fragile] \frametitle{Basically} %\vspace{2em} \begin{itemize} \item \texttt{at} -- Run a command once \item \texttt{cron} -- Run a command periodically \end{itemize} \end{frame} %} %--------------------------------------- \section{\texttt{at} command} \label{sec:at} %============================================================================== %\pause %\overlays{4}{% \begin{frame}[fragile] \frametitle{The \texttt{at} command}% \texttt{at} takes a time and a list of commands to run. Any output to \textsc{STDOUT} or \textsc{STDERR} will be mailed to the user running \texttt{at}. \par\vspace{1.8em}\par \begin{semiverbatim} \cmd{at 2pm} warning: commands will be executed using /bin/sh at> date \(\hookleftarrow\) at> ^D \(\hookleftarrow\) job 3 at 2002-05-08 14:00 \end{semiverbatim} \end{frame} %--------------------------------------- %============================================================================== %\pause %\overlays{4}{% \begin{frame}[fragile] \frametitle{The \texttt{at} command}% \par\vspace{1.8em}\par The current umask, working directory and environment (except for \textsc{TERM}, \textsc{DISPLAY} and \textsc{\_}) are saved and restored before running the job (unlike \texttt{cron}). \par\vspace{1.8em}\par The commands to run will be read from \textsc{STDIN} or from a file given with \opt{-f}. \end{frame} \subsection{Specifying the time for \texttt{at}} \label{sec:at-time-format} %\pause %\overlays{4}{% \begin{frame}[fragile] \frametitle{Example \texttt{at} time specifications}% \texttt{at} allows a \emph{very} flexible time format. \par\vspace{1.8em}\par \begin{description} \item[\texttt{17:36}] Run at 5:36pm today or tomorrow. \item[\texttt{9pm May 8}] Run at 9pm on May 8th. \item[\texttt{noon tomorrow}] Run at 12pm tomorrow. \item[\texttt{now + 2 hours}] Run in 2 hours. \end{description} \par\vspace{1.8em}\par See~\underline{at}(1) for more details. \end{frame} %\pause %\overlays{2}{% \begin{frame}[fragile] \frametitle{Queued jobs}% \texttt{atq} lists a user's pending jobs. \begin{semiverbatim} \cmd{atq} \rnode{A}{3} 2002-05-08 14:00 a gus \end{semiverbatim} \par\vspace{1.8em}\par \cmd{atrm \rnode{B}{3}} removes the queued job. \par\vspace{1.8em}\par \cmd{at -c \rnode{C}{3}} dumps the job on \textsc{STDOUT}. % \pause % %\onlySlide*{2}{% % \nccurve[linecolor=red,angleA=270,angleB=90]{->}{A}{B} % \nccurve[linecolor=red,angleA=270,angleB=90]{->}{A}{C} % }% \end{frame} % } \section{The cron System} \label{sec:cron} \subsection{crontab} \label{sec:crontab} %\pause %\overlays{4}{% \begin{frame}[fragile] \frametitle{\texttt{crontab}}% \texttt{crond} is a daemon that reads everyone's \texttt{crontab} information, spawning new tasks at the appropriate times. \begin{description} \item[\texttt{crontab \textit{file}}] Replace your crontab file with \textit{file}. \item[\texttt{crontab -l}] List your crontab. \item[\texttt{crontab -r}] Remove your crontab. \item[\texttt{crontab -e}] Edit your crontab (with \textsc{\$EDITOR}). \end{description} \end{frame} \subsection{crontab file format} \label{sec:crontab-file-format} %\overlays{6}{% \begin{frame}[fragile] \frametitle{\texttt{crontab} file format} A sample \texttt{crontab} file: \begin{semiverbatim} \rnode{min}{0} \rnode{hr}{7} \rnode{dom}{1} \rnode{mon}{jan} \rnode{wild}{*} echo "sleep in, you dont feel so good" \rnode{comment}{\# gratuitous noise} 0 17 * * \rnode{dow}{mon,wed,fri} \rnode{stdin}{wall\%meeting in 5 minutes\%} 0 9-18\rnode{step}{/2} * * \rnode{range}{mon-fri} \rnode{env}{\$HOME}/bin/cron.bihourly \end{semiverbatim} %\par\vspace{1.8em}\par \pause %\onlySlide*{2}{% \rnode{commentX}{Line based, hash comments, ignored blank lines, etc} %\nccurve[linecolor=red,angleA=270,angleB=90]{<-}{comment}{commentX}% %} \pause %\onlySlide*{3}{% \begin{itemize} \item \rnode{minX}{Minute (0-59)} \item \rnode{hrX}{Hour (0-23)} \end{itemize} % \nccurve[linecolor=red,angleA=270,angleB=90]{<-}{min}{minX}% % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{hr}{hrX}% %} \pause %\onlySlide*{4}{% \begin{itemize} \item \rnode{domX}{Day of month (1-31)} \item \rnode{monX}{Month (1-12 or jan-dec)} \item \rnode{dowX}{Day of week (0-7 or sun-sat)} \end{itemize} % \nccurve[linecolor=red,angleA=270,angleB=180]{<-}{dom}{domX}% % \nccurve[linecolor=red,angleA=270,angleB=90]{<-}{mon}{monX}% % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{dow}{dowX}% %} \pause %\onlySlide*{5}{% \begin{itemize} \item \rnode{stepX}{Step} \item \rnode{wildX}{Wildcard} \item \rnode{rangeX}{Ranges} \item \rnode{listX}{Lists} \end{itemize} % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{wild}{wildX}% % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{range}{rangeX}% % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{dow}{listX}% % \nccurve[linecolor=red,angleA=270,angleB=90]{<-}{step}{stepX}% %} \pause %\onlySlide*{6}{% See \underline{crontab}(5) for: \begin{itemize} \item \rnode{envX}{Environment variables} \item \rnode{stdinX}{Providing \textsc{STDIN}} \end{itemize} % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{env}{envX}% % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{stdin}{stdinX}% %} \end{frame} % } %--------------------------------------- %============================================================================== % %\overlays{6}{% % \begin{frame}[fragile] % \frametitle{\texttt{crontab} file format} % A sample \texttt{crontab} file: % \begin{semiverbatim} % \rnode{min}{0} \rnode{hr}{7} \rnode{dom}{1} \rnode{mon}{jan} \rnode{wild}{*}\\ % echo "sleep in, you dont feel so good"\\ % \vspace{1em} % \rnode{comment}{\# gratuitous noise}\\ % 0 17 * * \rnode{dow}{mon,wed,fri} \rnode{stdin}{wall\%meeting in 5 minutes\%}\\ % \vspace{1em} % 0 9-18\rnode{step}{/2} * * \rnode{range}{mon-fri} \rnode{env}{\$HOME}/bin/cron.bihourly % \end{semiverbatim} % \par\vspace{1.8em}\par % \pause % %\onlySlide*{2}{% % \rnode{commentX}{Line based, hash comments, ignored blank lines, etc} % %\nccurve[linecolor=red,angleA=270,angleB=90]{<-}{comment}{commentX}% % %} % \pause % %\onlySlide*{3}{% % \begin{itemize} % \item \rnode{minX}{Minute (0-59)} % \item \rnode{hrX}{Hour (0-23)} % \end{itemize} % % \nccurve[linecolor=red,angleA=270,angleB=90]{<-}{min}{minX}% % % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{hr}{hrX}% % %} % \pause % %\onlySlide*{4}{% % \begin{itemize} % \item \rnode{domX}{Day of month (1-31)} % \item \rnode{monX}{Month (1-12 or jan-dec)} % \item \rnode{dowX}{Day of week (0-7 or sun-sat)} % \end{itemize} % % \nccurve[linecolor=red,angleA=270,angleB=180]{<-}{dom}{domX}% % % \nccurve[linecolor=red,angleA=270,angleB=90]{<-}{mon}{monX}% % % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{dow}{dowX}% % %} % \pause % %\onlySlide*{5}{% % \begin{itemize} % \item \rnode{stepX}{Step} % \item \rnode{wildX}{Wildcard} % \item \rnode{rangeX}{Ranges} % \item \rnode{listX}{Lists} % \end{itemize} % % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{wild}{wildX}% % % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{range}{rangeX}% % % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{dow}{listX}% % % \nccurve[linecolor=red,angleA=270,angleB=90]{<-}{step}{stepX}% % %} % \pause % %\onlySlide*{6}{% % See \underline{crontab}(5) for: % \begin{itemize} % \item \rnode{envX}{Environment variables} % \item \rnode{stdinX}{Providing \textsc{STDIN}} % \end{itemize} % % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{env}{envX}% % % \nccurve[linecolor=red,angleA=270,angleB=0]{<-}{stdin}{stdinX}% % %} % \end{frame} % % } %--------------------------------------- \subsection{Setting up cron for root} \label{sec:cron-for-root} %\pause %\overlays{4}{% \begin{frame}[fragile] \frametitle{cron from root}% % \hypertarget{}{ } %\heading{} A few extra issues arise when editing \texttt{/etc/crontab} (and similar ``system'' crontab files): \begin{itemize} \item Don't use \texttt{crontab -e}, edit \texttt{/etc/crontab} directly. \item A new column (after timespec, before command) gives the user to the command run as. \item Distributions often create directories for ``common'' frequencies. It usually makes much more sense to place a script in there, rather than adding your own crontab lines. \par Debian, Red Hat runs any scripts in \texttt{/etc/cron.\{daily,weekly,monthly\}} -- but these are triggered from normal entries in \texttt{/etc/crontab}, so there's no real mystery here. \item \texttt{/etc/cron.d/*} is read in addition to \texttt{/etc/crontab} (they also have the extra user field). % \item \emph{(Debian specific?)} \texttt{/etc/cron.d/*} is read in % addition to \texttt{/etc/crontab} (they also have the extra user % field). \end{itemize} \end{frame} \section{anacron} \label{sec:anacron} %\pause %\overlays{4}{% \begin{frame}[fragile] \frametitle{\texttt{anacron}} \par\vspace{1em}\par Apparently some people turn their machines off. \par\vspace{1em}\par If your computer is always turned off at night (for example), then daily jobs which are usually scheduled to run in the wee hours, will never be run. This is a problem. \par\vspace{1em}\par \texttt{anacron} fixes this by running any missed jobs after a reboot (or other times, like AC-on for laptops). \end{frame} \subsection{\texttt{anacron} configuration: \texttt{anacrontab}} \label{sec:anacrontab} %\pause %\overlays{4}{% \begin{frame}[fragile] \frametitle{\texttt{anacron} configuration: \texttt{anacrontab}} \par\vspace{1em}\par Since anacron can't use the crontab files, it has its own simplified \texttt{/etc/anacrontab}. \par\vspace{1em}\par If you only use the standard \texttt{/etc/cron.{daily,monthly,weekly}}, then no further configuration will be necessary. Otherwise, see~\underline{anacrontab}(5). \par\vspace{1em}\par \emph{Note that the frequency of anacron jobs can only be specified in days.} \end{frame} \mode {% \begin{frame} \frametitle{Topics Covered} %\footnotesize %\begin{multicols}{2} \tableofcontents[pausesections,pausesubsections] %\end{multicols} % You might wish to add the option [pausesections] \end{frame} } \section{License Of This Document} \label{sec:license} \begin{frame} \frametitle{License Of This Document}% \raggedright% Copyright \copyright\ 2005, 2003 Angus Lees , Geoffrey Robertson and Nick Urbanik . \par Permission is granted to make and distribute verbatim copies or modified versions of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation---either version 2 of the License or (at your option) any later version. \end{frame} \end{document}