Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate username in tcl

Status
Not open for further replies.

ramana35

Technical User
Apr 23, 2012
14
HK
Hi,

I have a script that will add usernames into a permitted list.

Before adding it i would like to check if that username is really existed in my unix machine or not.

if it is shell scripting i can use id -a username and see exit status of that.

Could somebody tell how to do that in tcl script ?

Thanks inadvance

Thanks,
Kamma
 
Will a user have a home directory?
If so, you can use "file exists <pathname>" or "file isdirectory <pathname>"

_________________
Bob Rashkin
 
Hi

Are you talking about system users ? I would simply read /etc/passwd :
Code:
[b]set[/b] fil [teal][[/teal][b]open[/b] [green][i]"/etc/passwd"[/i][/green][teal]][/teal]
[b]while[/b] [teal]{[/teal][teal][[/teal][b]gets[/b] [navy]$fil[/navy] line[teal]]>=[/teal][purple]0[/purple][teal]}[/teal] [teal]{[/teal]
  [b]if[/b] [teal]{[/teal][teal][[/teal][b]lindex[/b] [teal][[/teal][b]split[/b] [navy]$line[/navy] [green][i]":"[/i][/green][teal]][/teal] [purple]0[/purple][teal]]==[/teal][green][i]"Kamma"[/i][/green][teal]}[/teal] [teal]{[/teal]
    [b]puts[/b] [green][i]"User found"[/i][/green]
  [teal]}[/teal]
[teal]}[/teal]
[b]close[/b] [navy]$fil[/navy]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top