UNIX System Administration CS 40: INTRODUCTION TO U NIX A ND L I NUX O P E R AT ING S Y STEMS
Objectives Discuss UNIX system administration, including the following categories: Job scheduling/monitoring User management/monitoring File system/disk space management Printer management
Job Scheduling/Monitoring Multiple jobs can be run in UNIX interactively They can be grouped together or made conditionally to run What ways have we learned already?
In the Past We ve learned that we can run a process in the background while running one currently (e.g. task &) What other ways are there?
Revisiting at We ve also used the at command to run processes in the future: $ at now+2min > date > who > Ctrl-D We can actually allow and deny user to use the command at To allow a user, add them to the file /usr/lib/cron/at.allow To deny a user, add them to the file /usr/lib/cron/at.deny
crontab We also have available a UNIX command, cron, which is the system process which will automatically perform tasks for you according to a set schedule We can edit this schedule from which these processes are performed through a program called crontab, short for cron table
Add a Job to the crontab Each job is one line in the crontab Each line must contain 6 pieces of information The first 5 pieces make up when to run the job The last piece is what job is going to run More specifically
Add a Job to the crontab (2) m h dom mon dow command A number (or list of numbers, or range of numbers), m, representing the minute of the hour A number (or list of numbers, or range of numbers), h, representing the hour of the day A number (or list of numbers, or range of numbers), dom, representing the day of the month
Add a Job to the crontab (3) m h dom mon dow command A number (or list, or range), or name (or list of names), mon, representing the month of the year A number (or list, or range), or name (or list of names), dow, representing the day of the week command, which is the command to be run, exactly as it would appear on the command line
Add a Job to the crontab (4) A "number" is an integer (e.g.) A "list of numbers" is a set of integers separated by commas (e.g. 15, 30, 45), which would represent just those three numbers A "range of numbers" is a set of numbers separated by a hyphen (e.g. 10 20), which would represent all the numbers from 10 through 20, inclusive
Add a Job to the crontab (5) Field Allowed Values minute 0-59 hour 0-23 day of month 1-31 month day of week 1-12 (or names) 0-7 (0 or 7 is Sunday, or use names)
Add a Job to the crontab (6) Names can also be used for the "month" and "day of week" fields Use the first three letters of the particular day or month (case doesn't matter) Ranges or lists of names are not allowed
crontab Example We want our job to run at 5 A.M., which would be minute 0, hour 5, every day of the month, every month, every day of the week We need to add a line to the bottom of the file which looks like this: 0 5 * * * /home/myname/scripts/do-every-day.sh
top Display system summary information as well as a list of tasks currently being managed by the Linux kernel
top Example [deepak@server1 ~]$ top top - 17:51:07 up 1 day, 2:56, 27 users, load average: 5.33, 29.71, 28.33 Tasks: 1470 total, 1 running, 1469 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.1%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 264114424k total, 253006956k used, 11107468k free, 66964k buffers Swap: 33554424k total, cached 3260k used, 33551164k free, 245826024k
top Example (2) PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1960 deepak 15 0 30452 3220 1540 R 2.3 0.0 0:00.78 top 2457 root 11-5 0 0 0 S 2.3 0.0 11:36.93 kacpid 2493 pmartprd 16 0 1397m 289m 9.8m S 0.3 0.1 18:36.07 pmrepagent 4639 pmartprd 15 0 787m 54m 4080 S 0.3 0.0 5:19.55 pmserver 14402 root RT 0 151m 5256 2872 S 0.3 0.0 1:41.40 multipathd 17886 root 10-5 0 0 0 S 0.3 0.0 0:07.41 kondemand/11
User Management/Monitoring While only one user can sit in front of the screen and use the keyboard at any one time, any number of users can log in to the system through the network To use the system, each user should have their own user account By doing this, we can have multiple users use the system at one time
UNIX Account Types There are three common types of accounts on a Unix system: Root account System accounts User accounts In addition, we will also talk about a concept known as the Group Account
UNIX Account Types: Root Account This is also called superuser Would have complete and unfettered control of the system A superuser can run any commands without any restriction This user should be assumed as a system administrator
UNIX Account Types: System Account Those needed for the operation of system-specific components (e.g. mail accounts and the sshd accounts) Usually needed for some specific function on your system Any modifications to them could adversely affect the system
UNIX Account Types: User Account Provide interactive access to the system for users and groups of users General users are typically assigned to these accounts Usually have limited access to critical system files and directories
UNIX Account Types: Group Account UNIX supports a concept of Group Account, which logically groups a number of accounts Every account would be a part of any group account UNIX groups plays important role in handling file permissions and process management
UNIX User Administration Files Here are the main user administration files: /etc/passwd: keeps user account and password information; this file holds the majority of information about accounts on the Unix system /etc/shadow: holds the encrypted password of the corresponding account; not all UNIX systems support this file /etc/group: this file contains the group information for each account /etc/gshadow: this file contains secure group account information
Managing Users in UNIX We have commands to manage users in UNIX: useradd: adds a user account to the system usermod: modifies the attributes of a user account already on the system userdel: deletes a user account from the system We also can modify the password of a user using the command passwd Use the d option to delete a forgotten password: passwd d
Managing Groups in UNIX Similarly, we have commands to manage groups in UNIX: groupadd: adds a group to the system groupmod: modifies the attributes of a group already on the system groupdel: deletes a group from the system
last Searches back through the file /var/log/wtmp (or the file designated by the -f flag) and displays a list of all users logged in (and out) since that file was created Examples: $ last $ last -f /nas/server/webserver/.log/wtmp
last Sample Output $ last root pts/1 10.1.6.120 Tue Jan 28 05:59 still logged in root pts/0 10.1.6.120 Tue Jan 28 04:08 still logged in root pts/0 10.1.6.120 Sat Jan 25 06:33-08:55 (02:22) root pts/1 10.1.6.120 Thu Jan 23 14:47-14:51 (00:03) root pts/0 10.1.6.120 Thu Jan 23 13:02-14:51 (01:48) root pts/0 10.1.6.120 Tue Jan 7 12:02-12:38 (00:35) wtmp begins Tue Jan 7 12:02:54 2014
wall Abbreviation of write to all Displays the contents of a file or standard input to all logged-in users
wall Examples alice@sleipnir:~$ wall Remember to brush your teeth! ^D alice@sleipnir:~$ wall <<< 'Remember to brush your teeth!
wall Examples (2) alice@sleipnir:~$ cat.important_announcement Remember to brush your teeth! alice@sleipnir:~$ wall.important_announcement # same as `wall!$` Broadcast Message from alice@sleipnir (/dev/pts/7) at 16:15... Remember to brush your teeth!
File System/Disk Space Management In the last lectures, we ve spoken about how the file system is laid out in its most basic form In the next couple of slides, we ll look at some of the commands which help us with how to maintain the file system and manage our disk space and how it s used
File System/Disk Space Management Commands Command du quota mount umount find Description Summarize disk usage Restrict the amount of disk space used Mount file systems and remote resources Unmount file systems and remote resources Search for files and perform actions when found
File System/Disk Space Management Commands (2) Command fsck dump restore tar Description Check and repair file systems Backup your file system(s) Restore a backed up file system Archive files
Printer Management Printing documents is an important part of any UNIX system Managing printers are manageable on a UNIX system as there are only a few commands to get this task done
Printer Management Commands Command lp/lpr lpstat cancel lpsched lpshut lpadmin Description Print, route, hold, and schedule a time for print jobs Print information about the status of the lp print service Cancel requests to line printer Start printer services Stop printer services Identify a printer to the lp print service
CUPS Stands for Common UNIX Printing System With so many different UNIX variants these days, can be difficult to develop printer drivers to support all the different UNIX printing systems Provides a common printing system interface, based on the Internet Printing Protocol (IPP)
CUPS (2) Defines how to: Manage jobs Set printer options Adds security features for printing over the Internet Once installed, provides a complete printer management environment that includes lp, lpr, and all of their commands