01/30/96, 4FAX# 2707 Preserve Login Session Information After Accounting SPECIAL NOTICES Information in this document is correct to the best of our knowledge at the time of this writing. Please send feedback by fax to "AIXServ Information" at (512) 823-4009. Please use this information with care. IBM will not be responsible for damages of any kind resulting from its use. The use of this information is the sole responsibility of the customer and depends on the customer's ability to eval- uate and integrate this information into the customer's operational environment. +----------------------------------------------------------+ | | | NOTE: The information in this document is NOT appli- | | cable for AIX 4.1. | | | +----------------------------------------------------------+ ABOUT THIS DOCUMENT In some versions of AIX (and UNIX), there is a problem with connection accounting forgetting about jobs that haven't logged off in the last 24 hours. The steps in this document correct this problem. | NOTE: APAR IX42292 corrected this problem in AIX 3.2.5. | The problem was corrected in AIX 3.2.5.1 and all later | releases. ABOUT THE PROBLEM The "runacct" command removes the contents of /var/adm/wtmp every night. Because of this, commands such as "last" lose track of users who logged in before the file was cleared. WORKAROUND The C program given below will take the /etc/utmp file entries for all currently logged-in users and append them to the existing /var/adm/wtmp file. This will allow "last" to report the user as being logged in and will allow "runacct" to report connection-accounting information for that user. How to Use the C Program To use the program below, run it immediately after running the "runacct" command. Typically, "runacct" is executed from the "adm" crontab with an entry of the form: 10 23 * * 0-6 /usr/lib/acct/runacct 2>/usr/adm/acct/nite/accterr > /dev/null Preserve Login Session Information After Accounting 1 01/30/96, 4FAX# 2707 Edit the "adm" crontab with the command "su adm -c crontab -e" and change that line to read: 10 23 * * 0-6 (/usr/lib/acct/runacct ;/usr/lib/acct/mkwtmp) 2>/usr/adm/acct/nite/accterr> /dev/null NOTE: The above two lines should be entered as a single line. The C Program Compile the C program given below and store in /usr/lib/acct/mkwtmp. The program must be made executable by the "adm" user and group. Depending on how you are viewing this document, some charac- ters in the following code may appear incorrectly. If the characters in the following list do not match their descriptions, be sure to change them in the code. +----------------------------------------------------------+ | | | [ left bracket | | ] right bracket | | | +----------------------------------------------------------+ Preserve Login Session Information After Accounting 2 01/30/96, 4FAX# 2707 #include #include #include main (int argc, char ** argv) { char *utmp_name = "/etc/utmp"; char *wtmp_name = "/var/adm/wtmp"; FILE *utmp_fp = 0; FILE *wtmp_fp = 0; int flag; time_t now; struct utmp utmp_rec; extern int optind; extern char *optarg; while ((flag = getopt (argc, argv, "u:w:")) != EOF) { switch (flag) { case 'u': utmp_name = optarg; break; case 'w': wtmp_name = optarg; break; default: fprintf (stderr, "mkwtmp [ -u utmp ] [ -w wtmp ]\n"); exit (0); break; } } if ((utmp_fp = fopen (utmp_name, "r")) == (FILE *) 0) { perror (utmp_name); exit (1); } if ((wtmp_fp = fopen (wtmp_name, "w")) == (FILE *) 0) { perror (wtmp_name); exit (1); } time (&now); while (fread (&utmp_rec, sizeof utmp_rec, 1, utmp_fp) == 1) { if (utmp_rec.ut_type == USER_PROCESS) { utmp_rec.ut_time = now; fwrite (&utmp_rec, sizeof utmp_rec, 1, wtmp_fp); } } exit (0); } Preserve Login Session Information After Accounting 3 01/30/96, 4FAX# 2707 READER'S COMMENTS Please fax this form to (512) 823-4009, attention "AIXServ Informa- tion". You may also e-mail comments to: elizabet@austin.ibm.com. These comments should include the same customer information requested below. Use this form to tell us what you think about this document. If you have found errors in it, or if you want to express your opinion about it (such as organization, subject matter, appearance) or make sug- gestions for improvement, this is the form to use. If you need technical assistance, contact your local branch office, point of sale, or 1-800-CALL-AIX (for information about support offer- ings). These services may be billable. Faxes on a variety of sub- jects may be ordered free of charge from 1-800-IBM-4FAX. Outside the U.S. call 415-855-4329 using a fax machine phone. When you send comments to IBM, you grant IBM a nonexclusive right to use or distribute your comments in any way it believes appropriate without incurring any obligation to you. NOTE: If you have a problem report or item number, supplying that number may help us determine why a procedure did or did not work in your specific situation. Problem Report or Item #: Branch Office or Customer #: Be sure to print your name and fax number below if you would like a reply: Name: Fax Number: ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ END OF DOCUMENT (wtmp.save.cmd, 4FAX# 2707) Preserve Login Session Information After Accounting 4