Need to find Unique not used Number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to find Unique not used Number
# 1  
Old 04-19-2009
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.
# 2  
Old 04-19-2009
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  
Old 04-20-2009
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  
Old 04-20-2009
please correct the first command line in the script


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



cheers,
Devaraj Takhellambam
# 5  
Old 04-20-2009
I think it was already correct. Still the same issue. Would you like me to post my entire script? Are you on a MAC?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count number of unique values in each column of array

What is an efficient way of counting the number of unique values in a 400 column by 1000 row array and outputting the counts per column, assuming the unique values in the array are: A, B, C, D In other words the output should look like: Value COL1 COL2 COL3 A 50 51 52... (16 Replies)
Discussion started by: Geneanalyst
16 Replies

2. Programming

Unique Number Identifying

I'm trying to solve the below problem for a number: Enter a number and if it has all unique digits print unique number else non-unique number. Eg: Input=123; Output=unique number Input=112; Output=Non-unique number The thing i tried is splitting the number into digits by using % operator... (2 Replies)
Discussion started by: Gautham
2 Replies

3. Shell Programming and Scripting

Concatenate lines with unique string AND number

In Bash using AWK or sed I need to convert the following file: ... numitem_tab0 =<p>1 KEYWORD</p><p>2 KEYWORD</p><p>3 KEYWORD</p><p>4 KEYWORD</p><p>5 KEYWORD</p>...<p>25 KEYWORD</p> subitem_tab0 =<p></p><p></p> ... numitem_tab6 =<p>1 KEYWORD</p><p>2 KEYWORD</p><p>3 KEYWORD</p><p>4 KEYWORD</p>... (2 Replies)
Discussion started by: pioavi
2 Replies

4. UNIX for Advanced & Expert Users

Count number of unique patterns from a log file

Hello Everyone I need your help in fixing this issue., I have a log file which has data of users logging in to an application. I want to search for a particular pattern in the log ISSessionValidated=N If this key word is found , the above 8 lines will contain the name of the user who's... (12 Replies)
Discussion started by: xtechkid
12 Replies

5. Shell Programming and Scripting

Finding the number of unique words in a file

find the number of unique words in a file using sort com- mand. (7 Replies)
Discussion started by: abhikamune
7 Replies

6. Shell Programming and Scripting

minimum number of unique key

input a 1 a 2 a -1 b 1 b 2 b 3 output a -1 b 1 Thanx ---------- Post updated at 09:42 PM ---------- Previous update was at 09:10 PM ---------- Ok I managed it (7 Replies)
Discussion started by: repinementer
7 Replies

7. Shell Programming and Scripting

display unique number

Hi, how i can display all the unique number from my random number script below; #!/usr/bin/perl use strict; my @alphanum = ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9); my $random = join('', map($alphanum,(1..5))); print "$random\n"; Thank You. (1 Reply)
Discussion started by: malaysoul
1 Replies

8. Shell Programming and Scripting

unique number for a date

Hello, In korn-shell, how can I do to have an unique number for a date done. I want to use it to have the number of days between two dates. Thanks in advance. (4 Replies)
Discussion started by: madmat
4 Replies

9. UNIX for Dummies Questions & Answers

Directory Inode Number Not Unique

Hi, I know that inode for each file is unique, but is it the for the directory? So far I found different directories has the same inode nubmer when you do ls -i, could some one explain why? Thanks a lot. (9 Replies)
Discussion started by: nj302
9 Replies

10. Shell Programming and Scripting

Script to count unique number of user loged in

Hi all, I am taking my first course in unix and having some problems. I would line to create a scrip that does the following: 1) will tell me the number of users logged in. If a user is logged more than once just count it only ones. 2) want to be able to display the number of users that... (1 Reply)
Discussion started by: elchalateco
1 Replies
Login or Register to Ask a Question