LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   can't 'userdel' OR How to fix a corrupt utmp? (https://www.linuxquestions.org/questions/linux-general-1/cant-userdel-or-how-to-fix-a-corrupt-utmp-226078/)

Plauderer 09-03-2004 06:14 AM

can't 'userdel' OR How to fix a corrupt utmp?
 
I wanted to use "userdel -r username" to delete a user account. Now whenever i try it states "User username is currently logged in". But he isn't. When i try "ps -u username" i get no processes for this user. How do i get rid of this user?

I read somewhere else that i need to delete "/var/run/utmp" and to "touch" a new one. But i don't think that this is a good idea.
The funny thing is when i use the command "w" i see correctly only root as logged in. Only the command "users" shows me the "dead" user i want to delete. But i read somewhere that "w" is using the utmp database aswell.

Now i googled some infos bout this and it sems a common problem to have a corrupt utmp database. Does anyone know how to fix that without rebooting the machine?

Thanks in advance,
Plauderer

masand 09-03-2004 06:30 AM

hi

utmp is a file,and u cannot edit the file without the utmp functions
see
man setutent
if u want to delete the entry from the utmp file,then u need to use the functions defined in the above man comand
and do u get this error everytime and do that users log into ur machine sometime or not ??
and the /var/run/utmp file is deleted and created new after each reboot
there is a switch in "who" which allows u to use the file for list of users
use the /var/log/wtmp there
u will get a list of all users logged in to ur machine from the begining

regards

Plauderer 09-03-2004 06:50 AM

First, thank you for your prompt answer! :)
Quote:

Originally posted by masand
hi

utmp is a file,and u cannot edit the file without the utmp functions
see
man setutent
if u want to delete the entry from the utmp file,then u need to use the functions defined in the above man comand
Don't have any such file / command. Maybe i have to install utmp-tools or something?
Quote:

and do u get this error everytime and do that users log into ur machine sometime or not ??
erm i think it was my own fault. I created the user for myself so i don't use root all the time. I logged in once and got stuck. So i killed the users processes. Since then i have this behaviour. :)
Quote:

and the /var/run/utmp file is deleted and created new after each reboot
I knew that already. It's just that i don't want to restart the machine only for this.
Quote:

there is a switch in "who" which allows u to use the file for list of users
use the /var/log/wtmp there
u will get a list of all users logged in to ur machine from the begining
I can't find a switch for who to choose wtmp as database. Neither in the manpages nor the info-section.

Thanks, Plauderer

masand 09-03-2004 11:50 AM

hi
if u could have gone throught the who --help throughly
section then u might have found out this

[root@gaurav root]# who --help
Usage: who [OPTION]... [ FILE | ARG1 ARG2 ]

-a, --all same as -b -d --login -p -r -t -T -u
-b, --boot time of last system boot
-d, --dead print dead processes
-H, --heading print line of column headings
-i, --idle add idle time as HOURS:MINUTES, . or old
(deprecated, use -u)
-l, --login print system login processes
--lookup attempt to canonicalize hostnames via DNS
-m only hostname and user associated with stdin
-p, --process print active processes spawned by init
-q, --count all login names and number of users logged on
-r, --runlevel print current runlevel
-s, --short print only name, line, and time (default)
-t, --time print last system clock change
-T, -w, --mesg add user's message status as +, - or ?
-u, --users list users logged in
--message same as -T
--writable same as -T
--help display this help and exit
--version output version information and exit

If FILE is not specified, use /var/run/utmp. /var/log/wtmp as FILE is common.
If ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual.

Report bugs to <bug-coreutils@gnu.org>.

here it is spcifies that u can spcefy a differnt file for parsing
so when i run

[root@gaurav root]# who /var/log/wtmp
root :0 Sep 1 23:42
root pts/1 Sep 1 23:43
root pts/2 Sep 1 23:43
root pts/4 Sep 1 23:43
root pts/3 Sep 1 23:43
root pts/4 Sep 2 00:49
root :0 Sep 2 21:57
root pts/1 Sep 2 21:57
root pts/2 Sep 2 21:58
root pts/3 Sep 2 21:58
root :0 Sep 2 22:30
root pts/1 Sep 2 22:30
root pts/2 Sep 2 22:31
root pts/3 Sep 2 22:31
root pts/4 Sep 2 22:55
root pts/4 Sep 2 23:13
root pts/5 Sep 2 23:43
root pts/2 Sep 3 01:00
root pts/2 Sep 3 01:05
root pts/2 Sep 3 01:18
root :0 Sep 3 08:37
root pts/1 Sep 3 08:37
root pts/2 Sep 3 08:37
root pts/3 Sep 3 08:48
root pts/2 Sep 3 09:52
root :0 Sep 3 22:18
root pts/1 Sep 3 22:18
root pts/2 Sep 3 22:19
root pts/3 Sep 3 22:20
root pts/4 Sep 3 22:27
[root@gaurav root]#

i get the above

anfd this the output from my
man setutent command
utmpname() sets the name of the utmp-format file for the other utmp
functions to access. If utmpname() is not used to set the filename
before the other functions are used, they assume _PATH_UTMP, as defined
in <paths.h>.

setutent() rewinds the file pointer to the beginning of the utmp file.
It is generally a Good Idea to call it before any of the other func-
tions.

endutent() closes the utmp file. It should be called when the user
code is done accessing the file with the other functions.

getutent() reads a line from the current file position in the utmp
file. It returns a pointer to a structure containing the fields of the
line.

-------------------------------------

see if this help u

regards


All times are GMT -5. The time now is 11:30 PM.