You are on page 1of 24
ontent ‘Automating Tasks avbatch The erontab Command trontae Format letcleron.*/ Directories naeron Viewing Processes ‘Managing Procosses Tuning Process Scheduling Process Accounting Enabling Process Accounting Solting Resource Lins via ulimit Lab Tasks 1. Creating and Managing User Cron Jobs 2 fdding System cron Jobs 3. Using BSD Pracess Accounting Chapter PROCESS ADMINISTRATION ‘Automatic Job Execution Unic systems have long provided the capability to script repetitive tasks; slong with tis capacity. they have also long had mechanisms in place for automatically cunning seripts or other programs to carry ‘ut daly tasks. It's important to recognize that even if@ system ‘bdministrator is not going to use these facilities directly to schedule ‘custom tasks, they stil must understand the facilities Because of th ‘extensive use made of them by the ayster, Examples of standard scheduled tasks present on a newly installed system include: automatic daily jobs in place to update man page index databases, clean out the /tap/ directory and process system logs and notify the administrator of anything unusual All of these jobs are periodic (e.g. daily, hourly) maintenance routines which would have to be manual run by an administer facies tke ter0n were notin pace. 102 Automating Tasks at & batch ~ Execute a tsk onco at sometime inthe future ron ~ Bxacute a task at recurring interval ‘nacron~ Ensures that regulary scheduled malntonance tasks are run, Such as ater system Inkallzation following a eystem halt RRA RAR RA RAR RRR R RAR AR ARAMA AAA sew wwwwwwwwwwwvwwwewwwwvwvowvwwvwuvuwd Creating An at Job 5 at now + 5 hours] {at echo Go Hone | mail -s "tine to leave” daxtgurulabs.con=] ap B®) Job Tat 2605-62-21 17242 Viewing and Deleting at Jobs $ ata 1 2365: $at-c1 H/bin/sh 4 atrun uid 4H pail vnask 22 HOSTNANE=stationlé.exanple.con; export HOSTHANE Seetelp oie fécho'co hone | tail -s “time to leaver daxtgurulabs.con Sata 1 5S atq at Job Queue: The at command can place jobs into specific queves labeled 2 through z and & through 2, withthe -g option. The at command uses the a quove by default and the batch command uses b by default. ‘Queues with higher letters run with increased niceness, 21 17242 a dketson at/batch + Execute 3 command at» speci ter bate = Bun jobs any ie when load average < 08 Use atd to spocty alternate las overage Can optionaly aso take time in the future ‘Time can be specified Ine flexible manner, Sat dm #3 days Current working directory, environment, umask are ‘Owner wil be emailed any output from commands ‘coase control /eto/at- alow and /ete/atdeny batch Syntax Using hatch is almost exactly like using at; the only difference betwen the two is that with batch, the time argument specifying ‘when the task should be run is optional. As long as the time ‘argument is omited, batch wal run the ob as con 2s the system load drops below a pre-defined level (0.8 by default). Il batch is given {a time argument, the job scheduled via batch wall tun as soon after the scheduled time as the system load is below the pre-defined level, ‘Accass Control with /ete/at {allow deny} Files The files /ete/at.allow and /ete/at.deny control which users can schedule at jobs It /etc/at.deny exists, users thet are listed in it an not use at; all other users can use at. If /etc/at.atlow exists, ‘users listed int can run at jobs; all other users cannot use at. If Jetc/at.altow exists, /etc/at.deny is ignored. if neither Jetc/at allow nor /etc/at.deny exst, only root is permitted to schedule at jobs. By default the system ships without an /etc/at.alow fil: only an empty /etc/at.deny fle exists, effectively allowing all users to schedule at jobs. Limiting access to at is an important, it often ‘overlooked, step when securing multhuser systems. 10-3 Cron Originally written by Brian Kernighan, cron is @ daemon that reads 3 ‘crontab fl, or fle, and executes jobs atthe times defined. Unike POSK at, cxond executes jobs at indefinite, reoccurring inowvals. With later editions of Unix, each user was given a crontab file, edited by the crontab command. ‘erond is enabled through the /ete/init.d/crond iit scrip. (Cron Access Controt ‘The erontab command can use either traditional files or PAM to ‘govern which users ean create cron jobs. ‘Access Control with /ete/eron.sllow and /ete/eron.deny 1 traditional les are being used, then usernames are placed, one per lin, in the /ete/eron.atlow and /etc/eron.deny files depending on ‘winother access will b respectively allowed or denied. Ifthe Zete/eron.aliow exists then the /etc/eron.deny will not be examined. In 8 detaut installation only an empty /ete/eron deny fle wil exist neither file exists then only root will be given access (see erontab(1) for details). ‘Access Control with PAM If instead, PAM is being used for access contol then generally the corresponding PAM configuration will use the pam_access.so module 10-4 cron Executes Jobs ata recurring interval = Jebs run every intl unt ois removed Each uor has a cron table which describes what to exocute and st ‘what interval crontab command used to create, modily, snd view a ron table ‘Feteloronsaltow * Irxists thon users must be sted in the foto use exontab Jetzleron. deny if exists then users must NOT bo itd in order to use crontab 1 Only eheckod if Jeto/oron.allow doesnot ona (called 3s an account module). To place limits on which accounts can Use eruntab, make entves in the /etc/ security/access.cont fe. AR AR RRR RAR RR ARR RRA MA AAA AAA VwC UUW EWEN UUW wENNwwENOwewues Using crontab as root ‘A normal user can only use erontab to view, edit of remove their ‘own eron table, The root user can use crontab to manipulate any User's cron table by ulizing the ~u option. For example, the following ermand wil alow root fo vw he con tbe crested by the User 4 crontab -u dhelson -1 ‘The cron table files reside in the /var/spool/eron/ directory. They should not be edited direct, but instead should be modified with the ‘crontab command. Bost Practices Many users ty to avoid use of the ~e option. On a standard QWERTY keyboard layout. the (] and (2 keys are sight next to each other. AS a result, many cron tables have been lost to fat fingers. One common practice used to avoid this accident isto create a tex file inthe User's home directory called crontab-usernane. Users can then edit that fle with 2 standard text editor and then use the crontab ‘command to import crontab-usernane. An inital crontab fle can be ‘teated from the current cron table by using the command crontab “> #ilenane, For example: § crontab -1 > ~/crontab-akelson § vi ~/erontab-dketson § crontab ~/eronteb-dkelson The crontab Command Ust/alsptay the currant eron table ‘crontab “1 ait the current cron table crontab ~= Remove the current eron table crontab =r Install the contents ct £{Lenane ws the current ern table crontab flenane Editors and erontak ‘When working with exontab, remember that it and many other Unie utilities use the stardard Unix environment variables to determine \wihich editor should be used. Depending upon the terminal type ‘currently being usec. erontab will use the VISUAL environmental ‘atiable to datermins which editor to use. If that is not possible, it will use the EDITOR variable. To change which editor crontab uses by dofauit, export appropriate values for those two variables: § export VISUALSSIxhich vi); export EDITOR=S(uhich ex) 10.8 crontab Syntax Tiene and dato fold: 2 minute of the hour (0-58) hour of the day (0-23) day of the month (1-31) 2¢month of the year (1-12) day of the wedk (0-7, where 0 and 7 a ‘An asterisk (*) stands for al values. Ranges are allowed with 2 dash. For example, 47 forthe day entry species days 4 through 7, which matches Thursday, Friday, Saturday ‘and Sunday. Lists are allowed and may contain a comma-separated element which can be a singlo number. alist such a5 °0,3.5 a range such as 0-5" or ‘even a combination of elements "05,7. Intorpreting the Day Fields “There are two day fields: day of the month and day of the week. It both of these fields are restcted, the command wal run when either field is @ match, ‘Tests against the output of the date command can be used to run jobs at intervals that cant be specified with cron syntax alone. For ‘example, the following would run a job on just Friday the 13th (not very useful, and the last day of each month (far more common). The Percent sign, used to specify the date format string, is normally 10-6 Sunday) crontab Format Minute Hour bey Month ay fof the of the of the of the of the our’ Day” “Wenth “Year Heck «6 interpreted as a cariage return by cron and must be escaped 1813 + + Lest “date +\ta" = Fil 66 command 14* + © [ §(date #\td -d tomorrow) == 61] 68 command ‘Advanced Syntax Step Values & Nicknames Linux systoms normaly use the Vise cron implementation, wich has 2 few extensions over the standard Uni crontab syntax. One extension isthe use of step values’ in conjunction with ranges or an fastersk Step values are specified by using /nunber notation ond ‘match for any value thet is a multiple of the specified step valve plus the starting value ofthe range. For example, the folowing is true if Used in the first fleld of cron enty (minute of hour) 0-59/2 => Equivalent t3 8,2,4,6.+.58,56,58 1659/2 > Equivalent 19 1,3,5,7...55,37,59 1/5 = Equivalent to 6,5,18,15.-.45,50,55 28-30/3 = Equivalent to 28,23, 26,25, ‘Cron also supports the use of the folowing special nicknames to ‘replace the five fields that specify when the job is run (reboot = Run once on boot Qyearly, @anaually = Equivalent to @ 811+ Gronthly = Equivalent to 8 81+ * Qveekly > Equivalentiog @* + 8 dally Equivalent 68+ + © @hourly = Equivalentto 8+ + + + POOR RAE AR AEA RIAA NNR WWW Wwe ww wow weUwUTUwUUwevewoUUs ‘The /ate/eron.d/ Dicectory For RPM created, scheduled jobs that need more flexibility, the Jetc/eron.d/ directory is available. Files in that dectory need to be in the regula crontab format withthe exception that after th dayot-the-week field, 9 new fiald exists. The new field specifies the Username thatthe command should execute as, pushing the ‘command-toxun field to the seventh position. This is just like the ‘syntax of the /ete/crontab main system crontab fie. ron Enhancements ‘These /etc/cron.*/ directories are a Linux enhancement tothe ‘normal cron system. The directories provide a quick and easy way for 2 system administrator to schedule jobs if only the interval between, Jobs is important. but the spect time at which the job cuns is Lnimportant. For example, a software developer or packsger might, say, "Hey, this new service needs this regular maintenance to run ‘once a week” In this case, @ script can be dropped into Jete/eron.weekly/ directory. This way. the system administrator ‘docides exactly when the regular weekly maintenance scripts run. ‘These directories also provide a very easy way for an RPM installation to schedule jobs, and an error-free removal of jobs when the RPM is emoved, without any need for @ programmatic method of editing cron tables, Al scrips run from the /ete/eron.*/ directories run with root privloges. letcicron.*/ Directories ‘The /etc/eron.d/ drsetory contains addtional system crontab files ‘Contents ao inthe samo format as the /etc/ crontab fle Executable commands (usually shell scripts) inthe remaining ‘etc/eren./ directories re scheduled to run on regulary recurring intarvaa: 1 fete/eron,tourly/ ‘feterecen. daly! Tets/eron-veekly/ Tetc/eron-nonthly/ Fed Hat Enterprise Linux 6 and the /ete/cro / directories Beginning with the inclusion of Crone, scripts located in ‘eron.daily/. cron.weekly/. and eron.nonthly/ directories ara ‘executed by anacron. The process of execution is as follows: 1. The cron daemon executes the commands) in Jete/eron.d/8hourly. 2, Tho /ete/éron.d/éhourly flo causes cron to execute the ceun-parts script 3. runeparts executes all the scrips in /etc/cron-hourly, including Panacron. 4, Sanacron launches anacron 5. anacron parses its contig file, identitying jobs for cron.daly, ‘ron.weekly and cron.monthly and executing as necessary. ‘The following table shows when the standard cron directories are ‘executed on RHELE: Directory Tir Tete/eron.hourly/ [st minute of every hour Tete/eron.daily/ [Between 3:05am and 10:55pm each day Tetc/eron.weekly/ | Between 3:25am and 11:10pm after 7 days since last execution Tete/eron.wonthly/ | Between 3:45am and 11:30pm after @ rhonth since last execution ‘anacron Startup ‘Anoeron ie frequently rforrod to 90 8 daemon or aowvioo, however it isnot a persistent process such as erond or ata. Instead, when run, ‘anacron reads its configuration fie, /ete/anacrontab, then exits. ‘Although anaeron does not run as a daemon, it may be regularly invoked to provide a similar service. anacron can be invoked manually. Tho simplest method of invocation is without arguments. To invoke anacroa fora specific ob, run the ‘Command with at least the Job. ident iffer as an argument # anacron cron. daily Jotc/anacronta The /etc/anacrontab configuration fle specifies what jobs anacron should monitor and run if necessary. The basic syntax used for entries in /etc/anacrontab is: delay job-identitier The period is specified in days %The de ay is specified in minutes The Job-ident fier isa simple text label identying jobs The command isthe command used to execute the job For each job, anacron checks whether that job has been executed in the last peried days. I the job has not been executed in that period, anacron runs the command after waiting for the number of minutes period ‘comand 108 Anacron *+ Capable of peiodeally checking if scheduled jobs have beon run 1 Patio is speed in days + lows specication of te delay befor job execution 1 Ensure execution a missed obs (e.g. due to sytem hat) Commonly used to ensure execution of cron. daily, ron.veetly, and cron.tanthty maltenance tasks Master configuration fle + /ete/anacrontab specified by the detay val might 100k tke thi: ‘An /ete/anaeronts Fle: JetcTanacrontab T @5 cron.daily —Fun-parts Jete/eron-daily 7. 18 cron.veekly run-parts /etc/cron.veekly/ 3875 cron.nonthly _run-parts /ete/eron.nonthly/ These enties cause anacron to run any missed /ete/cron. daily, Jeveferon.weekly/ of fevc/cron.nonthy/ tasks 65, 70 and 75 ‘minutes after system boot. Since they run so frequently, no anzeron command watches the /ete/cron.hourly/ tasks. The delay may be further increased if there is RANOOH DELAY value jt In tha /ete/anacrontab fle. This value provides a maximum ‘number of a possible random value that is added to the delay time, ‘As an example, if the delay time was sotto 15, and the RANDOH DELAY fenvironment variable is et to 68, then i is possible thatthe delay ‘ime will be any value from 15 to 75 minutes. ‘Anacron timestamps ‘Anacron stores the date of last execution in a fle named after the job under the /var/spool/anacron/ directory. A job named vogon.fleet ‘would result ina file named /vat/spool/anacron/vogon. fleet with a single fine of content, e.g, 26111821 (FY!) RRA RAR RAR RR ARAMA AR AAA RRA RASA CwYEwUWWUVOWWUWWYNVWVwTUTwWTUwUwUUs “To update the timestamp related to an Anacron job, modty the ‘Iax/speot/anacron job. identifier by hand. The ~u option wall, Update the timestamp to the current time. For example § anacron -u job. identifier Its important to nate thatthe -u option causes the timestamp to be ‘Updated, but does not result in immediate job execution. The original anacron facility introduced by Red Hat Linux 6.2, used times of 6,10, and 15 minutes after Boot. They were changed in RHL 0 after Red Hat conducted a survey regarding usage patterns in typical olice environments. They found that most people were away ftom their asks for about 20.80 minutes fom fest arriving to work in the moming and booting their system. Reesons include scheduled & Impromptu meetings, hunting someone dowa to get questions answered, o information needed, grabbing a coffee, meeting with lionts, ete. 10-9 top ‘The top command displays processes sorted by column (CPU usage bby default. updating the display every 3 seconds. Press the space bar to manually refresh. This provides for @ convenient way of locating processes eating up a significant portion of a resource. Top ‘also provides 2 command interface, such as forking processes. For @ list of supported commands. type [5] from within the top interface. Useful commands include [to kil processes, [to select which fields are displayed, or BEML] to change the field sort order. Viewing Processes pS standard process listing tool * Uses /pree/ as information source 5 Gan cukomize cpinved ovout ¢ Supports 85D (aux) and SyaV options (ae) cep ~ pa and grep combined etree "Shows process Wes top / atop "Provides summary information and stats on each running process in realtime fashion * Displays beckgroundedisusponded processes invoked tom shot Process information comes from /proc/ Tools ike ps, top and pstree use the /proc/ filesystem to collet the data they need to operate. An easy way to see this “in action is to Commands make when running: 4 strace ps tee amp, staté¢(*/proc/7321", {st_node-s_1FDIR|0855, st_size6, ...)) = @ open(*/proc/7221/stat", 0_ROONLY) read(7, *7221 (pine) §°7127 7221 7127 348*..., S11)"= 199 elese(7) + snip. Remember that there are times when the /proc/ filesystem may not bbe mounted and available: for example when booted to a minimal ‘recovery environment during system repair. The absence of the ‘prec! flesystom vil use these peogrems tof RRR RRR ERR ARR RRR AAR RAR RRA Pw CwwwwwwwwwwwUUUNeUUwUNwYwwuNWUeD Customizing Output Format Normally ps will tuncate each ine at the edge of the terminal when using the ful format =f (or -F) option. To force ps to splay the Complete command line for each process, add aw (or two for Unlimited width. For example: 4 ps enw ‘To obtain output with only specific desired columns, use the =o ‘option. This can eliminate the need to process the cutout of ps with AWK or other tools. For example. 4 ps 00 pid,userjcnd To search the output ofthe ps command without having grep show Up inthe output, Use @ regular expression trick othe pare ‘command: 4 ps -ef | grep {blash 4 porep -Le bash Threads In eats releases of Linux, threads would show up as separste processes inthe output of ps, pstree and top. This was changed to Show only processes, In ore to see threads inthe Output of PS, use the =m option. 10-11 ‘Signaling a Process Processes react to various signals sent to them by other processes or ‘manually by the system administrator. Common signals include SIGHUP (hang up detected, such 2s from a dropped dumb-terminal connection), STOTERM (request process termination), and SIGSTOP (pause, or stop, a process without termination). ‘The basie mathod for manualy signaling a process is to provide the signal and PID to the RLUL command. This fist requires the ‘administrator to look up the PID with the ps command. However, ‘thar tools exist that allow the edmin to signal a process by ‘command name, terminal. group, oF user name. For example, the KAULaLL command will signal all processes with command names ‘matched by a specific regular expression. Linux and a few other Unix variants (Solaris, for example) include ‘ditional commands to facilitate process management. Commonty ‘2dministrators will want to find the process ID of a specific process. For example, i the OpenSSH server's coniiguration fle is chenged, tho daemon needs to be noted by sending ta SIGRUP. Typically, this would first necessitate determining the PID of the daemon, by doing something like: # ps wef | grep sshd root 3387-1 @ Feb23? 09:68 /usr/sbin/ssha With pgrep this can be done in one command: # porep sshd 10-12 Managing Processes wit ' Sond signals (default TER to processes witiatt «+ Sends signals to processes by name orep, itt 1 Morage processes by terminal, group, username, PID, of ‘commend name. + Avalabo for both Linux and Unie adit ‘Manage processes by terminal group, username, PD, ‘commend name. «+ Svalable for Unux 387 4 prep -Le ssh 3367 /ast/sbin/sshd 27361 ssh roottstation!3.ctass2 53467 /osr/bin/ssh-agent ‘The -1 option causes the process name to be listed along with the PID. The =£ option does a pattern match agains the full command line, not just the binary. Just as pgrep allows searching of process space ty name rather than process iD, pkitl allows signaling of processes by name rather than PID. Using pgrep to send a SIGHUP to the OpenSS+{ server would require two commands, a pgrep command to determine sshas PID ‘and then a kill -HUP command to that PID. pki allows those two ‘commands to be combined: 4 pRiLL -aUP sshd By dofault, pki wil signal all processes whose rames match the ‘specified regular expression. For example, phil ssh would kil any running ssh, ssh-agent, sshd, etc. To signal only processes that match exactly the full patter, use the ~x option. For example, pki =x vi wil kil vi, but not vin, or evince. a POW EVEOW WU eEUWUYOUVWUUVUWVTUWOWwUVED Nico values (On a multitasking system the kemel has to regulate the amount of (CPU time that is allocated to each process. Generally the kernel does this without any input from the user. One value considered by the kKemmel when allocating CPU time isthe process nice value {an integer betwen -20 and 19} Seting a postive nice value signals to the kernel process scheduler that the process is voluntary giving up some of is fait share of CPU time from the perspective of other processes, this is a‘rce” thing to do). In contrast, setting @ negative ice value indicates that this process desires more than its fair share. Lowering the nice value ofa process can only be done as the root ‘ser however, all users can increase the nice valve oftheir own, processes. ts good to be nice When @ command is launched its given 9 default nice value of 0, unless the parent process has an altered nice value wich will be inherited by the chil process (.e. if your shell had @ rice value of 3, then any command launched would have @ default nice value of 3.) In the folowing example, the command myprogram is launched with 2 nice value of 5: § nice -n 5 ayprogran ‘The nice command will use the default value of 10 when a nice value ie not epectig, (Le, tho equivalent of - 18), Tuning Process Scheduling Launch a process with an adjusted schedullg priority: 1 Mody the scheduling priority of running process: * venice 18 pid 4 Feniee -18 pid 4 renice 0 -p pid 1 Enlce by terminal, group, usemame, PID, or command name renice ‘The renice command is used to change the nice value ofa running process. In the following example a process was started with @ nice value of 6; renice is used to set a now nice value of 10: § pater ayprogran rd § renice 10 3306 3306: old priority 5, new priority 18 Ifa specific nice value isnot provided to the renice command a default nice valve of zero is used, 10-13 Setting up Process Accounting Process accounting requires bath kemeltevel support for logging processes and userevel aplications which log processes and extract information from process logs. Kemel support for process, ‘ccounting is selected by enabling the option BSD Process ‘ecoonting when building the kernel, Linux enables this by defaut. ‘The user commands for working with process accounting are provided by the psacct RPM. A default installation of RHEL does ‘ot include psacet, and process accounting will not work without it 10-14 Process Accounting What is process accounting? ‘For each process run records user and cpu time used ny use prem aecountiog? 1 track actors of users 1 rack tors of eministeatore Funetionality largely replaced by new Audit kernal subsystem RRR RR RR RRA RRA RRA ARR RAR ORAS VOC wrwwwwwwrVVewewwYorwowwwuud ‘The ae command is used to view summaries of user logins. It actually works even when process accounting is not boing used. To do this, it accesses the /var/tog/wexp file. It accepts a variety of options to Configure how it produces output. The folowing command will produce summaries of login times per account: fac -p akelson 661.72 berost 58.26 ericker 36.52 root 789.21, total 1507.71 ‘The following will produce daily login summaries: fac -d Mov 1 total 145.67 ov 15 total 1.15 Today total 92.31 Process logging can be turned on and off using the aceton ‘command. For example, the fllowing wil turn on logging of all ‘processes to the default logfile, /ar/account/pacct, while aceton by itself will turn off process logging: 4 accton /var/account/pacet Enabling Process Accounting * Enables and disables process accounting «+ Summarizes user command Histories lasteons “Displays commands oxecutec by sors Only show command, does rt show arguments Commands logged wihen i terminates ‘Summarizes user login statistics ‘Once process accounting has been turned on, 6a can be used to view processes. The most popu option to use with sa is ~u, to tell ito print user names: fsa-u nobody 61 cpu 436k men gzip nobody cpu S54 men sh root cpu 615k men rad + root = 18.81 cpu 1Zk men. 8 0. mpg123, lasteomm \astcom is 2 useful utility for searching through the command logs by several criteria. For exemple, the following wall search for command oF specific user activity respectively: 1 lastoom comand # lasteomm user 10-45 Using ulimit ‘The wlinit command is built into the shel, providing contol over the ‘consumption of resources avaliable to the shell and to processes, ‘started by it. The basic syntax of the ulimit command is: ulinit (-stacdftmpstuv (1iniel} ‘Tho value of Limit can be a number in the unit specified for the resource, oF the value “unlimited.” The =I and -8 options specity whether to set a hard or soft limit; if nether is spectieg, the ‘command applies to both hard and soft Kits It Lint is omitted, the ‘current value of the sof limit ofthe resource is printed, uniess the ‘option is used. ‘Soltlimits may be increased by each user. A hard limit may only be increased by the root user. Both hard and soft limits can exist on 2 particular resource simultaneously. The soft limit defines the limit. \which is enforced, while the hard imit defines the celing value where ‘only root can increase the limit, ‘The following options and descriptions are taken from the bash(1), ‘man page end apply to the Bash ulinit bultin command. Another Conveniant way to access this list of options i to run help ulimit from the Bash shell prompt, 10-16 Setting Resource Limits via ulimit Ulinit ~ Provides control over the resources avallale to the shell nd to processes started by it Can be used in login scripts Users can view and change the limits [Poton|Descipion SS C—~d a__[Alleurrent lita are reported =e |The maximum size of core fies created =a__| The maximum size of @ process's data segment =£ |The maximum size of files created by the shell =t__|The maximum siz thet may be locked into memory -a__| The maximum resident set size =| The maximum number of open file deseriptors =p__| The pipe size in 512-byte blocks (this may not be set) =8__|The maximum stack size [-t___|The maximum amount of epu time in seconds [=u |The maximum number of processes available to a user [=v |The maximum amount of vitual memory available to shel ARR RRR RR AAR RR AR SARA RAAT IID wrowwowwowwwwrwwouweUTUweUwwwwuWe”d ‘Task 1: Creating and Managing User Cron Jobs Page: 1018 Time: 10 mi Requirements: (1 station) ‘Task 2: Adding System cron Jobs Page: 1021 Time: § minutes Requirements: 1 station) Tas jsing BSD Process Accounting 22 Time: 18 minutes Requirements: © (1 station) Lab 10 Eetimated Time: 50 minutos 10-17 Oe an ot unr ean tn Tas k Sti and at sa ern ‘ask 1 Requirements Creating and Managing User B (1 station) Cron Jol Relevance 1 2 3) 4) 5) 10-18 ‘Cron is a convenient solution to run jobs, such @s backups, on 2 regularly ‘scheduled interval ‘As the guru user, use the crontab command to edit the gurc user's crontab: 5 whoami gun § crontab -e When the toxt editor exits, if the fil was changed, the exontab command installs the saved contents as the new exontab, ‘Schedule a cron job to run every five minutes broadcasting "Hello from guru" to ‘every user logged ito the system: (Fiera ti Tile created by crontab - STE + +7 + echo “Hello from gurus [wall Verify thatthe new job was added to the crontab: 8 crontab -1 A/S 8 © echo “Hello from guru" | vall Redirect the output of crontab -1 toa file in the guru users home directory sea 5 crontab -1 > crontab-guru Notice how close the 2 key isto the [6 key “Accidentally” delate the gure users crontab: $ crontab -r PRR OR EL EER AREA AAA ARRAN ewww wow wwwuwUUwwUUUUewowUuUuwOd (ops! The entire crontab has just been lost. Notice thatthe crontab command id not ask for confirmation before deleting the user's crontab. 6) Verity that there is no crontab installed for guru: 5 crontab -1 ‘no erontab for guru 7) Ads an sdeltional task to the crontab-gurs fle: i /hane//guru/erontab-gure W75 © + * + echo “Hello fom Gun | wall +]3-59/5 + + + + echo “this is a test message" 8) Install the crontab-guru file as the new erontab for the guru user: $ crontab crontab-guru 9) Verity that the new crontab was successfully installed 5 crontab -L 115-4 * * + echo “Hello from guru" | wall + Message seen by usts who ae curently logged en 3459/5 #8 + + echo “This is a test messag *Ouputemaled 10 the ga use. 10) Wait ive minutes to give the cron jobs @ chance to run: § sleep 380; echo -e “Ding!\a" “This ight be 2 god tne for shor break. 11) Once bath of the cron jobs have run, the mail command can be used to read the message sent: Snail fee nip ss. */vaz/spoot/naii/guru": 6 messages 6 new *Depencng on how much ime has elapsed, you wil soe oN 1 gurufstationk Tue Jan 2 11:55 19/666 Cron echo 2 diflsing mbar of eral M2 gurustationx Tue Jan § 19/685 cron cgurotstations> wall N 3 gurufstationx tue Jan 19/666 Cron echo N 4 gurutstationt Tue Jan 19/685 Cron walt 10-19 12) 13) 10.20 N $ guruéstationy Tue Jan 2 12:65 19/685 cron wall N_6 guruéstationx Tue Jan 2 12:85 19/666 Cron echo = «Pressing B=) repeated wil ply al ofthe see snip... messages, oe by on, 2 quit “The following actions require administrative privileges. Switch to @ root login shell saul Passvord: makeitso GS] ‘As root, remove the guru users crontab file: 4 crontab

You might also like