- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- user account -delete
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2011 04:48 AM
тАО02-18-2011 04:48 AM
I am totally new in scripting env.I need a script for the following scnerio.
we have some user account now a days they don't exist.So we want to delete those.What we want to do we will take name one by one from the /etc/passwd field & search whether their home directory exists or not , if they exists then we will said user exists if not then it will show a msg that do u want to delete, if we press yes then it will delete that user.we want to fire the script from a centrilized server which will ssh to other servers & chec this.. Could you please help me..
Regards,
Ani
Solved! Go to Solution.
- Tags:
- passwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2011 06:09 AM
тАО02-18-2011 06:09 AM
Re: user account -delete
This is one way to begin:
# cat ./seeker
#!/bin/sh
OLDIFS=${IFS}
IFS=":"
while read USER X X X X HOMEDIR X
do
if [ ! -d ${HOMEDIR} ]; then
echo "'${HOMEDIR}' does not exist for '${USER}'"
fi
done < /etc/passwd
IFS=${OLDIFS}
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2011 06:14 AM
тАО02-18-2011 06:14 AM
Re: user account -delete
Find attached a script that find users without homedir on a system.
First try a test using this syntax:
#sh scriptname.sh test
Also review the -READ ME FIRST- note placed inside.
For a real execution:
#sh scriptname.sh
Be careful with masive user deletion.
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2011 08:29 AM
тАО02-18-2011 08:29 AM
Re: user account -delete
Tnx.I will fire this in a test box first.I hv some question.
if [ ! -d $USERDIR ]
--what does it mean?
as i will fire this to test box i want to remove this if [ "$1" = "test" ]
regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2011 09:12 AM
тАО02-18-2011 09:12 AM
Re: user account -delete
if [ ! -d $USERDIR ]
Inside of a question (if), "-d" validates if is a directory file's type, and "!" is a negation. This is the question's meaning: If the content of $USERDIR variable is not a directory?
>>as i will fire this to test box i want to remove this if [ "$1" = "test" ]<<
You do not needs delete this question, it's only be useful if you execute the shell script followed of the second argument "test", if you will fire just executes the shell script without next argument.
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2011 10:51 AM
тАО02-18-2011 10:51 AM
Re: user account -delete
if [ "$INPUT" = "y" ]---#upto this i understood.#
then
if [ "$1" = "test" ]
then
echo "This user: $USERNAME will be removed"
else
userdel $USERNAME
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2011 11:56 AM
тАО02-18-2011 11:56 AM
Re: user account -delete
Since you are totally new to shell scripting, I urge you to look at the code already provided along with a quick-read of:
http://docs.hp.com/en/B2355-90046/index.html
The aforementioned document is a good starting point for an overview of a shell and the shell's basic syntax. Look specifically at the POSIX and Korn shell section. The POSIX shell is HP's default shell. You will find that the variations of the 'ksh' (Korn) shell are natural cousins of that as is the GNU Bash shell which adds a great number of rich features.
Avoid the 'csh' shell for serious work of any kind.
This reduces your initial reading to a small subset of this guide, notably section IV.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2011 09:42 PM
тАО02-18-2011 09:42 PM
Re: user account -delete
could u pls reply ...
if input=yes then what it will check can you please explain the below lines
if [ "$INPUT" = "y" ]---#upto this i understood.#
then
if [ "$1" = "test" ]
then
echo "This user: $USERNAME will be removed"
else
userdel $USERNAME
Ani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2011 10:55 PM
тАО02-18-2011 10:55 PM
SolutionOk, I'll traduce to pseudo code the script:
Do while all lines at /etc/passwd filtered by fields 1 (username), 3 (userid) and 6 (user home dir), setting ENTRY whit this values (separated by ":" char) for each entry. ie: ENTRY=bob:1323:/home/bob
Assing to USERNAM the first value of ENTRY variable (separated by ":" char). USENAM=bob
Assing to USERIDE the second value of ENTRY variable (separated by ":" char). USERIDE=1323
Assing to USERDIR the third value of ENTRY variable (separated by ":" char). USERDIR=/home/bob
if(1) $USERDIR not is a directory
then(1) display the mesagge for deletion and read user answer (INPUT)
if(2) $INPUT = "y"
then(2) if(3) script execution have a first argument ($1) with value "test"
then(3) just display "This user: $USERNAME will be removed" no real deletion action will be done.
else(3) a real deletion of user ($USERNAME) will be done
endif(3)
endif(2)
endif(1)
endo
Also "else(3)" action includes the -READ ME FIRST- consideration. Here all lines starting with # char are interpreted as comments. Please understand this lines to avoid files with "nouser" inside your system.
NOTE: the first line is not a comment, this line indicates the shell interpreter that will be use when run the script (#/usr/bin/sh).
The class is over, you owe me a lot of points! :)
Best regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2011 12:53 AM
тАО02-19-2011 12:53 AM
Re: user account -delete
Thank you..last question ..I also want to write a script like you people..could you please give me some URL or guide me from where i will start, u explain me every thing in a very simple way but in books it's complicated. so please please give me some URL so let me know from where i will start.please guide me ..
Regards,
Ani