LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-13-2009, 05:38 PM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 810

Rep: Reputation: 39
Logging out a user account within a script


Hi there --

I am writing a shell script that will do a snapshot of a local hard drive, but there is a need for all users to be logged off when the script is run. This is due to the user accounts being NIS, and the home directories in question are NFS mounts which are supposed to be unmounted prior to the snapshot being made.

What would the correct syntax be in order to accomplish this? One idea that I had was the following:

Code:
# su - <user>
# logout
If this works, how could I go about in checking for all logged in users, and repeating the above process? Thanks.
 
Old 03-13-2009, 06:53 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Quote:
Originally Posted by kaplan71 View Post
What would the correct syntax be in order to accomplish this? One idea that I had was the following:

Code:
# su - <user>
# logout
If this works, how could I go about in checking for all logged in users, and repeating the above process? Thanks.

That won't work. At best, it will just create a new login shell for the given user and just log out of that shell.

If you have text-mode users, I would first ask the users to log out, then wait for a length of time:

Code:
echo "Please log out to unmount all NIS accounts" | wall
sleep 60
You then need to kill any login shells that persist:

Code:
who -lH
The column labelled PID contains the process IDs of any login shells, which can be used to kill the shell process. Rather than killing the script outright, you want to tell these shells to log out so that their logout scripts run:

Code:
kill -HUP pid
 
Old 03-14-2009, 12:07 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,430

Rep: Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787
To check for logged in users/open files, look at
fuser
lsof
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
add user account with pass from script juanctes Linux - General 3 02-03-2008 01:50 PM
How to program shell script to automate mass user account creation? EsAsher Linux - General 2 06-30-2007 08:41 AM
samba - add user script - User account does not exist itzamecwp Linux - Server 2 01-18-2007 10:52 PM
Prevent user account from logging in but allow su to account DejaCpp Linux - General 4 07-26-2006 11:44 AM
error logging into user account ambelos Linux - Laptop and Netbook 2 01-22-2004 08:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration