The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
TAHI Test Suite 3.0.13 (IPv6 Conformance Test Tool branch) iBot Software Releases - RSS News 0 04-06-2008 09:20 AM
Keithley Introduces Linux-Based RF Parametric Test Systems - Test and Measurement.com iBot UNIX and Linux RSS News 0 07-23-2007 07:30 AM
Variables being worked on inside of loops yongho UNIX for Dummies Questions & Answers 7 06-13-2005 08:42 AM
useradd dorilevy UNIX for Advanced & Expert Users 2 10-18-2004 11:15 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-26-2005
Registered User
 

Join Date: Aug 2005
Posts: 6
Exclamation test to see if useradd worked

I am trying to write a script that does a useradd -G <group> <user> but you cannot modify the user if he/she is logged on. How could I check to see if the user is on or if the user has been added to the group successfully? I plan on having the script sleep for a couple mins if the user is on then attempt to add the user to the group again.

Last edited by doublejz; 08-26-2005 at 07:03 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 08-26-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
useradd sets the exit status. So just check the exit status as you would for any other well designed program.
Reply With Quote
  #3  
Old 08-26-2005
vertigo23's Avatar
Registered User
 

Join Date: Jul 2005
Location: SF, CA
Posts: 67
Quote:
Originally Posted by Perderabo
useradd sets the exit status. So just check the exit status as you would for any other well designed program.
To elaborate on that, bash (if that's what you're using) will let you use an IF statement to check exit status in a very readable way:

Code:
if useradd <args>; then
  do stuff
else
  do other stuff
fi
Reply With Quote
  #4  
Old 08-27-2005
Sergiu-IT's Avatar
Registered User
 

Join Date: Mar 2005
Location: Transilvania
Posts: 125
Hi !
In addition to what vertigo23 and perderabo said, you can check the $? variable. This will tell you the error code returned by the last command (in your case, useradd). If the result is 0, then the last command exited without any error. If it tells you something else, check the manual pages or google to see what it means.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0