?? unx38.htm
字號:
<BR></P>
<UL>
<LI>Link the /sbin/init.d/acct file to the /etc/rc0.d/K22acct.
<BR>
<BR><B>$ link /etc/rc0.d/K22acct /sbin/init.d/acct</B>
<BR>$
<BR></LI></UL>
<OL>
<LI>Link the /sbin/init.d/acct file to the /etc/rc2.d/S22acct.
<BR>
<BR>$ <B>link /etc/rc2.d/S22acct /sbin/init.d/acct</B>
<BR>$
<BR>
<BR>When the system is booted, the init process will run these scripts to start the system accounting option. The last thing you need to do is add entries in the crontab file. The crontab file is used by cron to run programs at predetermined times. See
Chapter 20, "Scheduling Processes," for more details on cron. We need to add ckpacct, runacct, monacct, and dodisk to the crontab file to finish the accounting system setup.
<BR></LI>
<LI>Edit the crontab file to add these utilities.
<BR>
<BR>$ <B>crontab -e</B>
<BR></LI>
<LI>Add /usr/lib/acct/ckpacct to check /var/adm/pacct every hour to archive the pacct file after its size is more than 500 blocks.
<BR>
<BR>0 * * * * /usr/lib/acct/ckpacct
<BR></LI>
<LI>Add /usr/lib/acct/runacct to run daily to process the accounting files to prepare daily and cumulative summary files. It is recommended that you run this file at off-hours of the morning. You can pick any time. For this example, we will use 1:30 a.m.
<BR>
<BR>30 1 * * * /usr/lib/acct/runacct 2> /var/adm/acct/nite/fd2log
<BR>
<BR>/var/adm/acct/nite/fd2log is a log file that you look at to verify that runacct is running cleanly.
<BR>
<BR></LI>
<LI>Add /usr/lib/acct/monacct to run monthly. The monacct file takes data stored in the /var/adm/acct/sum directory and creates a monthly report of all daily totals.
<BR>
<BR>30 3 * 1 * /usr/lib/acct/monacct
<BR></LI>
<LI>Add /usr/lib/acct/dodisk program to do disk usage accounting. It is recommended that you run this program once a week and before runacct is executed daily.
<BR>
<BR>00 22 * * 4 /usr/lib/acct/dodisk
<BR></LI>
<LI>Shutdown and reboot your system to activate the accounting system.
<BR>
<BR></LI></OL>
<H3 ALIGN="CENTER">
<CENTER><A ID="I12" NAME="I12">
<FONT SIZE=4><B>The Accounting System Programs</B>
<BR></FONT></A></CENTER></H3>
<P>Remember the processes that you add to the crontab file. Those processes are essential to keep track of your system usage.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I13" NAME="I13">
<FONT SIZE=3><B>runacct</B>
<BR></FONT></A></CENTER></H4>
<P>/usr/lib/acct/runacct is a shell program that is executed every day to process system usage. It will create daily summary files for the /usr/lib/acct/prdaily and /usr/lib/acct/monacct programs. prdaily is run by runacct to write daily accounting
information to the /var/adm/acct/sum/rprtMMDD file. MMDD is the month and day the file was created. monacct is the month usage report, which will be covered later in this chapter. There can be one of these files for every day of the week. runacct actually
writes information to several files.
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>/var/adm/pacct?</P>
<TD>
<P>Contains process information. ? represents the incremented /var/adm/pacct file.</P>
<TR>
<TD>
<P>/var/adm/wtmp</P>
<TD>
<P>Contains user information</P>
<TR>
<TD>
<P>/var/adm/fee</P>
<TD>
<P>Contains fees accessed for usage</P>
<TR>
<TD>
<P>/var/adm/acct/nite/disktacct</P>
<TD>
<P>Contains the disk space usage</P></TABLE>
<P>You can find the output of the runacct program in the /var/adm/acct/nite directory. Other files in the /var/adm/acct/nite directory are as follows:
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>lock and lock1</P>
<TD>
<P>These files may or may not exist. If they do exist, runacct will not run. It will "think" that it is already running. If you get an error concerning these files during an attempted execute of runacct, remove them with rm (remove command).</P>
<TR>
<TD>
<P>lastdate</P>
<TD>
<P>This file records the last date that runacct was executed. This file is checked to prevent runacct from being executed more than once daily.</P>
<TR>
<TD>
<P>fd2log</P>
<TD>
<P>This file contains the message generated by runacct. It will contain important error information in case runacct fails to run.</P></TABLE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> If runacct does have an error, root will be notified by mail. It will write information to /var/adm/acct/nite/fd2log and remove the lock files.
<BR></NOTE>
<HR ALIGN=CENTER>
<H4 ALIGN="CENTER">
<CENTER><A ID="I14" NAME="I14">
<FONT SIZE=3><B>dodisk</B>
<BR></FONT></A></CENTER></H4>
<P>The /usr/lib/acct/dodisk shell script cumulates disk usage information. This shell script program runs three programs.
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>diskusg</P>
<TD>
<P>Collects file data by reading the file INODES</P>
<TR>
<TD>
<P>acctdusg</P>
<TD>
<P>Collects file statistics in the file system</P>
<TR>
<TD>
<P>acctdisk</P>
<TD>
<P>Formats the data from diskusg or acctdusg</P></TABLE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> Only one of the file data accounting programs needs to run. /usr/lib/acct/diskusg and /usr/lib/acct/acctdusg output the same information, but how they approach the information differs. diskusg is much
faster than acctdusg because it looks at the lowest level of file information in the INODE. To toggle between the two, the dodisk can invoke the -o option. The following script:
<BR>
<BR>/usr/lib/acct/dodisk <I>/dev/dsk/c1t0d0s2</I>
<BR>
<BR>will run the diskusg method against the device file name of /dev/dsk/c1t0d0s2. If the device name is not specified, then diskusg will look in the /etc/vfstab file and process all the devices. This is very similar to the fsck command that looks at the
file system's INODE's when it checks the file system at boot time. This is much faster. The following script:
<BR>
<BR>/usr/lib/acct/dodisk -o <I>/user</I>
<BR>
<BR>will run the acctdusg method against the /user file system mounting point. If the mount point is not specified, the root mounting point is used.
<BR>
<BR>Remember, if you want to use acctdusg, add the -o option to the dodisk line in the crontab file.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>acctdisk will write the formatted output to the /var/adm/acct/nite/disktacct file. This file will have the following information about users' files on the system:
<BR></P>
<UL>
<LI>The user's login name
<BR>
<BR></LI>
<LI>The user's id number
<BR>
<BR></LI>
<LI>The number of blocks in use in the user's files
<BR>
<BR></LI></UL>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="warning.gif" WIDTH = 37 HEIGHT = 35>WARNING:<B> </B>dodisk stores all this information in /var/adm/acct/nite/disktacct. Each and every time dodisk is executed, it overwrites the /var/adm/acct/nite/disktacct file. Executing dodisk more than once
daily should be avoided.
<BR></NOTE>
<HR ALIGN=CENTER>
<H4 ALIGN="CENTER">
<CENTER><A ID="I15" NAME="I15">
<FONT SIZE=3><B>chargefee</B>
<BR></FONT></A></CENTER></H4>
<P>If you are in a Computer Services department or part of a service provider, you may elect to charge other departments or users for the resource they use. UNIX has provided a program called chargefee that will charge your user for a number of services.
The charges that are generated by chargefee are stored in /var/adm/fee. Say that carolynp sends me a message to mount a tape for her on my system and I charge $1.50 for every mount.
<BR></P>
<PRE>$ chargefee carolynp 1.50
$</PRE>
<P>An entry in /var/adm/fee would be made having carolynp, her user id number, and 1.50. Later in my monthly accounting report charges for mounting tapes, restoring files, etc. can be polled into an invoice billed to the user. Most places will normally
charge for processor time and disk space on a monthly basis. The monacct program, which you can read about next, will generate a nice report to run charge-back scripts against the invoice users.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I16" NAME="I16">
<FONT SIZE=3><B>monacct</B>
<BR></FONT></A></CENTER></H4>
<P>monacct runs monthly, or you can run it whenever your fiscal period ends, to generate files that summarize the statistic files created by dodisk and runacct. These files are stored in the /var/adm/acct/fiscal directory. After the monacct program is run,
the files created by dodisk and runacct removed and reset for the next fiscal period.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I17" NAME="I17">
<FONT SIZE=3><B>acctcom</B>
<BR></FONT></A></CENTER></H4>
<P>The acctcom utility allows you to see the accounting system at any given time. You can execute this command from the command line with several different options.
<BR></P>
<PRE>$ acctmon -a</PRE>
<P>This will show the average statistics about processes.
<BR></P>
<PRE>$ acctmon -r</PRE>
<P>This will show the amount of user time per total time (system time plus user time).
<BR></P>
<PRE>$ acctmon -u zachp</PRE>
<P>This will show all the processes belonging to the user zachp.
<BR></P>
<PRE>$ acctmon -O 20</PRE>
<P>This will show all the processes running longer than 20 seconds.
<BR></P>
<P>To see more options for the acctcom command, please refer to your man pages. acctcom will look in the /var/adm/pacct? files for these little records.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I18" NAME="I18">
<FONT SIZE=3><B>Daily Reports</B>
<BR></FONT></A></CENTER></H4>
<P>runacct generates a number of reports.
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>The Daily</P>
<TD>
<P>Shows the usage of ports on your system.</P>
<TR>
<TD>
<P>The Daily Usage</P>
<TD>
<P>Shows the system resource used by your users during the daily period.</P>
<TR>
<TD>
<P>The Daily Command Summary</P>
<TD>
<P>Shows the commands run on your system and resources those commands used. This report can be essential in helping you determine the process that might bottleneck your system.</P>
<TR>
<TD>
<P>The Last Login</P>
<TD>
<P>Tells you the last time a login id was used by a user. This report can help you remove unused login id's and directories associated with those id's.</P></TABLE>
<H4 ALIGN="CENTER">
<CENTER><A ID="I19" NAME="I19">
<FONT SIZE=3><B>Daily Report</B>
<BR></FONT></A></CENTER></H4>
<P>The Daily Report can be found in the /var/adm/acct/nite/lineuse file.
<BR></P>
<PRE>$ cat /var/adm/acct/nite/lineuse
Apr 06 01:33 1994 DAILY REPORT FOR excelsior Page 1
from Tue Apr 05 05:10:41 1994
to Wed Apr 06 01:31:20 1994
1 runacct
1 accton
TOTAL DURATION IS 5155 MINUTES
LINE MINUTES PERCENT # SESS # ON #OFF
ttyp01 1541 30 4 9 5
ttyp10 2564 50 25 8 6
ttyp13 1050 20 15 3 4
TOTALS 5155 100 44 20 10
$</PRE>
<P>The detail of this report column by column are as follows:
<BR></P>
<TABLE BORDER>
<TR>
<TD>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -