Results 1 to 5 of 5
hi all. im new to scripting.
im trying to add a list of users which are all stored in a data file. so far, i can only get it to ...
- 02-12-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 3
bash scripting
hi all. im new to scripting.
im trying to add a list of users which are all stored in a data file. so far, i can only get it to do this for the first line in the data file.
this is what i have so far.
#!/bin/sh
var=`cat /root/data`
for i in $var; do
exec adduser -s /sbin/nologin $i; password $i
done
any help would be greatly appreciated.
- 02-12-2008 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
put double quotes and see how it goes
otherwise, use a while loop insteadCode:for i in `cat filename` do exec adduser -s /sbin/nologin "$i"; password "$i" done
otherwise, it both did not work, show us samplesCode:while read -r i do exec adduser -s /sbin/nologin "$i"; password "$i" done < file
- 02-12-2008 #3Just Joined!
- Join Date
- Feb 2008
- Posts
- 3
Thanks. For some reason its still only executing it for the first line in the file.
- 02-12-2008 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
So you are saying, "run adduser, and don't continue with the remainder of the code in this script, exit after the first run of adduser". To fix this part of the script, just remove the exec:exec: exec [-cl] [-a name] file [redirection ...]
Exec FILE, replacing this shell with the specified program.
-- excerpt from man bash
There are situations when you should use exec, but this is not one of them ... cheers, drlCode:... do adduser -s ...
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 02-12-2008 #5Just Joined!
- Join Date
- Feb 2008
- Posts
- 3
thanks heaps. that works fine now


Reply With Quote