-->
Previous | Table of Contents | Next |
Notice the pipe between the sort and mail commands in the preceding example. The command field can contain pipes, semicolons, arrows, or anything else you can enter on a shell command line. At the specified date and time, cron runs the entire command field with a standard shell (bash).
To specify a sequence of values for one of the first four fields, use commas to separate the values. Suppose you have a program, chkquotes, that accesses a service that provides stock quotes and puts the quotes in a file. To get those quotes at 9 a.m., 11 a.m., 2 p.m., and 4 p.m. on Monday, Tuesday, and Thursday of every weekand definitely on the 10th of March and Septemberuse the following entry:
* 09,11,14,16 10 03,09 01,02,04 chkquotes
Put the command lines into a file by using vi or some other editor that allows you to save files as text files. Assume that you put your commands in a file named cronjobs. To use crontab to put the file where cron can find it, enter this command:
crontab cronjobs
Each time you use crontab this way, it overwrites any crontab file you may have already launched.
The crontab command has three options:
See Setting the Shell Environment, p. 344
In all these cases, crontab works with the crontab file that has your login name. If your login name is mcn, your crontab file is /usr/spool/cron/crontabs/mcn. The crontab command does this automatically.
The system administrator and users share responsibility for making sure that the system is used appropriately. When you schedule a process, be aware of the impact it may have on the total system. Linux allows you, as the system administrator, to grant access to the at, batch, and cron commands to all users, specific users, or no users (or to deny access to individual users).
TROUBLESHOOTING:
The commands I put in my crontab file dont work. The cron command runs your crontab entries by using the Bourne Again shell (bash). Your entries fail if you use shell features not supported by bash. For example, the Public Domain Korn shell (pdksh) allows you to use either a tilde (~) to represent a home directory or the alias command to designate aliases for certain commands.When I try to use the at command, Im told I dont have permission to use it. You havent added your login ID to the /etc/cron.d/at.allow file.
I tried to use the at now command to run a command immediately. No matter how fast you type, at now always responds with the message ERROR: Too late. The best alternative is to use the batch command to run the command for you. You can, however, use at now +5 min to run the command in five minutes. After you press <Return>, type quickly to enter your command before the five minutes expire.
You know that Linux is a multiuser, multitasking operating system. Because so many people can do so many things with the system at the same time, users find it useful to determine whos using the system and what processes are running, as well as to monitor processes.
Knowing that others can keep track of the commands you enter is important. Most users cant access your files without your permission, but they can see the names of commands you enter. Also, you (as the system administrator) or someone else who has the root password can peruse all the files on the system.
Although you dont have to be paranoid about privacy on a Linux system, you should know that the system can be monitored by anyone who wants to take the time to do it. The information you can gain about whats going on in the system is more useful than just satisfying curiosity: By seeing what jobs are running, you can appropriately schedule your tasks. You can also see whether a process of yours is still active and whether its behaving properly.
The purpose of the who command is to find out whos logged in to the system. The who command lists the login names, terminal lines, and login times of users now logged in.
The who command is useful in many situations. If you want to communicate with someone on the computer by using the write command, for example, you can find out whether that person is on the system by using who. You can also use who to see when certain users are logged in to the computer to keep track of their time spent on the system.
Using who to List Users Logged In to the System
To see everyone whos now logged in to the system, enter who. You see a display similar to the following:
$ who root console Dec 13 08:00 ernie tty02 Dec 13 10:37 bkraft tty03 Dec 13 11:02 jdurum tty05 Dec 13 09:21 ernie ttys7 Dec 11 18:49 $
This listing shows that root, ernie, bkraft, and jdurum are now logged in. It shows that root logged in at 8 a.m., bkraft at 11:02, and jdurum at 9:21. You can also see that ernie is logged in to two terminals and that one login occurred at 6:49 p.m. (18:49) two days earlier (which may be some reason for concern, or it may just be ernies usual work habits).
Using Headers in User Listings
Several options are available with who, but this chapter describes how to use only two to monitor processes on the system:
-u | Lists only users who are now logged in |
-H | Displays headers above each column |
Previous | Table of Contents | Next |