Linux Cron Tab

  • View
    6

  • Download
    2

Embed Size (px)

DESCRIPTION

Linux Cron Tab

Text of Linux Cron Tab

  • LINUX+ LAB SERIES (LX0-102)

    Lab 5: crontab and at

    Document Version: 2015-04-30

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    Development was funded by the Department of Labor (DOL) Trade Adjustment Assistance Community College and Career Training (TAACCCT) Grant No. TC-22525-11-60-A-48; The National Information Security, Geospatial Technologies Consortium (NISGTC) is an entity of Collin College of Texas, Bellevue College of Washington, Bunker Hill Community College of Massachusetts, Del Mar College of Texas, Moraine Valley Community College of Illinois, Rio Salado College of Arizona, and Salt Lake Community College of Utah.

    This workforce solution was funded by a grant awarded by the U.S. Department of Labor's Employment and Training Administration. The solution was created by the grantee and does not necessarily reflect the official position of the U.S. Department of Labor. The Department of Labor makes no guarantees, warranties or assurances of any kind, express or implied, with respect to such information, including any information on linked sites, and including, but not limited to accuracy of the information or its completeness, timeliness, usefulness, adequacy, continued availability or ownership.

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    1

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    Contents

    Introduction ........................................................................................................................ 2 Objective ............................................................................................................................. 2 Linux+ LX0-102 Exam Objectives ........................................................................................ 3 Lab Topology ....................................................................................................................... 4 Lab Settings ......................................................................................................................... 5 1 Scheduling Processes with the at Command .............................................................. 6 2 Controlling Access to the at Command .................................................................... 11 3 Scheduling Processes with the crontab Command .................................................. 12 4 Controlling Access to the crontab Command ........................................................... 15 5 Exploring System crontabs ........................................................................................ 17

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    2

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    Introduction

    This lab provides guidance on performing Lab 5: crontab and at of the Linux+ LX0-102 course, using a NETLAB+ system. By performing this lab, students will learn how to schedule processes to execute in the future using the at and crontab commands. Objective

    The following tasks will be performed:

    1. Learn how to schedule future tasks with the at command. 2. Limit access to the at command. 3. Learn how to schedule future recurring tasks with the crontab command. 4. Limit access to the crontab command. 5. Manage system crontabs.

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    3

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    Linux+ LX0-102 Exam Objectives

    This lab will cover the topics for the following LX0-102 objectives: 107.2 Automate system administration tasks by scheduling jobs

    1. Manage cron and at jobs. 2. Configure user access to cron and at services.

    The following is a partial list of the used files, terms, and utilities:

    a. /etc/cron.d{daily,hourly,monthly,weekly} b. /etc/at.deny c. /etc/at.allow d. /etc/crontab e. /etc/cron.allow f. /etc/cron.deny g. /var/spool/cron/* h. crontab i. at j. atq k. atrm

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    4

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    Lab Topology

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    5

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    Lab Settings

    The information in the table below will be used to complete the lab. Additional details will be provided within the task sections as required.

    System Username/Password

    CentOS Server sysadmin/netlab123

    Ubuntu Server sysadmin/netlab123

    Fedora Workstation sysadmin/netlab123

    Ubuntu Workstation sysadmin/netlab123

    All Machines root/netlab123

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    6

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    1 Scheduling Processes with the at Command

    There are circumstances where you may want to schedule a time in the future for a process to run. For instance, you might want to run the who command at 2AM to see who is logged on the system at this time. If you only want to run a command (or set of commands) one time in the future, you can use the at command to schedule this.

    1. Click on the Fedora Workstation icon in the pod topology to launch the virtual machine.

    2. The virtual machine will display a login screen. Make sure sysadmin is in the user field. Enter the password netlab123 and press Enter.

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    7

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    3. Once you have logged in, a terminal window may appear. If it does not, click on the Kickoff Application Launcher, the f, in the lower left corner of the desktop. In the search bar, type konsole and click on Konsole, which will launch a terminal window:

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    8

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    4. Switch to the root user in the terminal window that opens: su -

    netlab123

    5. Run the following commands to schedule the who command to run at 2AM the following morning. Note that where you see (in the screenshot below) you will be typing Control-D (^D):

    at 2AM

    at> who > /tmp/whothere

    at> ^D

    Your output should be similar to the following:

    Note that if you do not redirect the output of at commands, the output will be emailed to you.

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    9

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    6. The at command provides a very flexible system for specifying what time to run the command(s). Execute the following command and scroll down to read how to specify times:

    man at

    Your output should be similar to the following:

    7. To see the at jobs that are scheduled for your account, use the atq command: atq

    Your output should be similar to the following:

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    10

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    8. To remove an at job from the queue, use the atrm command as show below: atq

    atrm 1

    atq

    Your output should be similar to the following:

  • Linux+ Lab Series (LX0-102) Lab 5: crontab and at

    11

    This work by the National Information Security and Geospatial Technologies Consortium (NISGTC), and except where otherwise noted, is licensed under the Creative Commons Attribution 3.0 Unported License.

    2 Controlling Access to the at Command

    1. To disallow access to the at command, add the user name to the /etc/at.deny file. Each line in this file should contain a single user name. In this case, open the /etc/at.deny file in the editor of your choice and add the following line:

    sysadmin

    Your output should be similar to the following:

    2. To verify, exit from the root shell back to the sysadmin account and attempt to run the following at command:

    exit

    at 2AM

    Your output should be similar to the following