Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-19-2009
Registered User
 

Join Date: Oct 2008
Posts: 50
Need to find Unique not used Number

Wrote a script to create a hidden account in OS X. It works perfect but I need to check if the UID is already in use before I tried to create the account.


Code:
dscl . list /Users UniqueID | awk '{print $2}' | while read UIDS
do
if [ "$UIDS" == "$2" ]; then
echo "UID Is Already in USE"
i=`expr "$2" - 1`
echo "$i"
exit 0

This helps but if the selected UID minus (one) is in use the script proceeds. I need a loop and decrement the number until it finds one that is not in use.
Sponsored Links
  #2 (permalink)  
Old 04-19-2009
devtakh devtakh is offline Forum Advisor  
Registered User
 

Join Date: Oct 2007
Location: Bangalore
Posts: 598
use a while loop, something like this

dscl . list /Users UniqueID | awk '{print $2}' | while read UIDS
do
while ( "$UIDS" == "$2")
do
echo "UID Is Already in USE"
i=`expr "$2" - 1`
done
echo "$i"
done

cheers,
Devaraj Takhellambam
  #3 (permalink)  
Old 04-20-2009
Registered User
 

Join Date: Oct 2008
Posts: 50
I get command not found for every UNIQUE ID. If it's easier can anyone help me start my UID at 499 and count down until it finds one that is not in use?
  #4 (permalink)  
Old 04-20-2009
devtakh devtakh is offline Forum Advisor  
Registered User
 

Join Date: Oct 2007
Location: Bangalore
Posts: 598
please correct the first command line in the script


dscl . list /Users UniqueID | awk '{print $2}' | while read UIDS



cheers,
Devaraj Takhellambam
  #5 (permalink)  
Old 04-20-2009
Registered User
 

Join Date: Oct 2008
Posts: 50
I think it was already correct. Still the same issue. Would you like me to post my entire script? Are you on a MAC?
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
display unique number malaysoul Shell Programming and Scripting 1 06-02-2008 09:14 AM
Need to find only unique values for a given tag across the files sudheshnaiyer UNIX for Dummies Questions & Answers 8 09-03-2007 01:53 AM
unique number for a date madmat Shell Programming and Scripting 4 11-30-2006 12:35 PM
Directory Inode Number Not Unique nj302 UNIX for Dummies Questions & Answers 9 05-22-2005 12:34 PM
Script to count unique number of user loged in elchalateco Shell Programming and Scripting 1 09-30-2002 12:32 PM



All times are GMT -4. The time now is 05:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0