Technical article 105610

I want to clear my system of users who are not logged in.

OpenServer 6.0.0OpenServer 5.0.0OpenServer 5.0.2OpenServer 5.0.4OpenServer 5.0.5OpenServer 5.0.6OpenServer 5.0.7UnixWare 7.0.0UnixWare 7.0.1UnixWare 7.1.0UnixWare 7.1.1UnixWare 7.1.2UnixWare 7.1.3UnixWare 7.1.4Open UNIX 8

Written · Last revised

Problem

DOS or Windows TCP/IP clients that have logged into an
SCO UNIX system through telnet turn off their DOS or WINDOWS
system or enter <Ctrl><Alt><Del> after their DOS or Windows
session has hung.  The UNIX "who" command on the SCO system
reports them as still logged in.
- or -

DOS or Windows TCP/IP clients that have logged into an SCO UNIX system through telnet exit the SCO session normally, but the UNIX "who" command on the SCO system reports them as still logged in.

- or -

A system that is licensed for a certain number of users is unable to allow the number of licensed users to log in.

- or -

The "who" command shows users who are not logged in.

- or -

The system is no longer usable as the number of configured pseudo ttys are consumed by users who are no longer logged in.

Rebooting the system does not seem to clear any of the above problems.

Cause

The /etc/utmp, /etc/wtmp, /etc/utmpx or /etc/wtmpx may be corrupt.

The utmp file and related files record user and accounting information for commands such as "who", "finger" and "login".

The utmp file contains information about the current state of the
system, including one record for each logged-in user.  The login
command writes or removes a record to the utmp file each time a user
logs in or out.

The wtmp file contains historical data; each time a user logs in or out, a record is written to wtmp.

The utmpx and wtmpx files contain additional information such as the name of the remote host for users who log in via the network. This information is not transferred to utmp or wtmp.

The utmp and its related files are open to login and other commands
to write information about users' activities and expect that the
commands that wrote to those files will clear a user properly
after exiting a login session.  In some instances this may not
occur, especially if the user is using a DOS or Windows TCP/IP
stack.
- and/or -
The /etc/auth/system/ttys file may be corrupt.

The ttys file (/etc/auth/system/ttys) contains entries for each terminal that can be used to log in to the system. Authentication programs use this database to determine if logging in is permitted on a particular terminal.

Users and processes related to a user's session may still be
consuming ttys even after the user has exited an SCO telnet
session.  At some point the policy manager may not be able to
function.

Solution

/utmp, wtmp, utmpx and wtmpx may have become corrupt.

As the user root, create the following script to clear utmp, wtmp, utmpx and wtmpx prior to shutdown:

----------------------cut here---------------------------------
#!/bin/sh
# /bin/clearutmp
#
# clear utmp, wtmp, utmpx and wtmpx on shutdown or bootup
#
> /etc/utmp
> /etc/wtmp
> /etc/utmpx
> /etc/wtmpx
----------------------cut here---------------------------------

Save the clearutmp script to /bin and run:

# chmod 700 /bin/clearutmp

The above script can be run manually prior to shutting the system down, or you can add the following lines at the end of /etc/bcheckrc to clear /etc/utmp, wtmp, utmpx and wtmpx during system start-up.

As an example, add the following to the end of /etc/bcheckrc:

#
# Added to clear /etc/utmp, wtmp, utmpx and wtmpx on boot
#
> /etc/utmp
> /etc/wtmp
> /etc/utmpx
> /etc/wtmpx

Note: It is not recommended that /bin/clearutmp be run unless the system is about to be brought down. The utmp and related files contain valuable information about system state and start-up times; clearing those files during run-time can cause unpredictable results.

The following relates to OpenServer only:
The /etc/auth/system/ttys file may be corrupt.

As the user root, create the following shell script to clear the /etc/auth/system/ttys file:

------------------------------------cut here------------------------------------
#!/bin/sh
# /bin/clearttys
RC=0
mv /etc/auth/system/ttys /tmp/ttys.$$
touch /etc/auth/system/ttys
chown auth:auth /etc/auth/system/ttys
cd /tcb/bin
./ttyupd </dev/null >/dev/null 2>&1
RC=$?
if [ "$RC" -ne 0 ]; then
  echo "*ERROR* Running ./ttyupd (RC=$RC)" > /tmp/clearttys.log
else
  /tcb/bin/ale /etc/auth/system/ttys pttyupd </dev/null >/dev/null 2>&1
  RC=$?
# Both 0 and 2 exit codes are success... exit 2 is used when there
# are no ttys to update
  if [ "$RC" -ne 0 ] && [ "$RC" -ne 2 ]; then
    echo "*ERROR* Running ./pttyupd (RC=$RC)" >> /tmp/clearttys.log
  fi
fi
exit "$RC"
------------------------------------cut here------------------------------------

Save the clearttys script to /bin and run:

# chmod 700 /bin/clearttys

The script, clearttys, can be run while the system is in multiuser mode when the "who" command displays users who are not logged in or use crontab to set up cron to run clearttys at regular intervals.

NOTE:     To see where the user's have logged in from, ie. their IP address,
          use the "finger" command.

The same command is also applicable to UnixWare7/Open UNIX 8 and OpenLinux as the "who -xm" command is only applicable to OpenServer.

NOTE:     TROUBLESHOOTING:

- Seeing "Can't find utmp entry for ptty" errors and unable to log in. The /etc/issue information is displayed on the screen but the login prompt doesn't appear.

Clear down the /etc/utmp, utmpx, wtmp and wtmpx files in the same as described above then reboot your server.

In addition, check that there are no additional network services that might be conflicting, such as "bootp" or a service also using port 23.

See also

For information on the ttyupd command, which achieves the same result as the script above, see:

ta100737 - "I want to know what the /etc/utmp and /etc/wtmp files contain."

ta104588, "Rebuild ttys file from inittab including pseudo ttys after crash."

ta105755, "How to use the cwtmp utility to clear stale entries from utmp and related files."

cron(C), crontab(C), ttys(F), rc(ADM), bcheckrc(ADM), who(C), w(C), last(C)

From the Xinuos technical article database, record 105610. Reproduced with permission. The original is at www.sco.com/ta/105610, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.