Results 1 to 10 of 11
goodmorning (here anyways),
I've been busy with scripting with linux. A simple useradd script and a userdell.
Script:
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
useradd $i
...
- 09-02-2010 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 9
#!/bin/sh
goodmorning (here anyways),
I've been busy with scripting with linux. A simple useradd script and a userdell.
Script:
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
useradd $i
echo $i"123?" | passwd --stdin "$i"
echo; echo "User $username password changed"
done
`more userlist.txt ` means there is a userlist.txt file where the username should be. Allso this scripts makes a standard password that is 123[username].
When i typ ./user.txt in the shell, i get this output:
Script:
more
Changing password for more.
User password changed
userlist.txt
useradd: Account 'userlist.txt' already exists.
Changing password for userlist.txt
User password changed
same happens when i do userdell with a simalair script
what goed wrong? I made this script a long tima ago and then it works great. Did i mist something?
- 09-03-2010 #2
hm. more is a interactive program that you shouldn't use in a script. use cat instead.
- 09-03-2010 #3Just Joined!
- Join Date
- Sep 2010
- Posts
- 9
'cat userlist.txt' ?
- 09-03-2010 #4
Kind of:
Note that ' and ` quotes have a different meaning.Code:#!/bin/sh for i in `cat userlist.txt ` do echo $i useradd $i echo $i"123?" | passwd --stdin "$i" echo; echo "User $username password changed" done
- 09-03-2010 #5Just Joined!
- Join Date
- Sep 2010
- Posts
- 9
well, that worked.. but now i get the following message:
changing login shell for basdijkstra
enter the new value, or press return for de default.
chsh: Shell must be a full path name.
chsh: 'basdijkstra 123' does not exist.
chsh: 'basdijkstra 123' is not executable
Login Shell [/bin/bash] : Warning: "basdijkstra 123" is not listed in /etc/shells.Shell Changed
User password changed
- 09-03-2010 #6Please refer toCode:
#!/bin/sh for i in `cat userlist.txt ` do # remove whitepaces i="${i/ /}123" echo $i # add user useradd -p password $i # change password not with passwd, but usermod (see man usermod) echo "User $username password changed" done
for proper usage. For example the --stdin flag is unknown to me. Oh, and NEVER call useradd on a login that already exists. Do proper exists checks before.Code:man passwd man usermod man useradd man adduser man id
Last edited by Kloschüssel; 09-03-2010 at 09:51 AM.
- 09-03-2010 #7Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Better is to avoid the use of cat in a loop, don't go for the Useless Use of Cat Award:
Code:#!/bin/sh while read i do echo "$i" ... ... done < userlist.txt
- 09-03-2010 #8
In the end everybody gets something new to learn from time to time.
- 09-07-2010 #9Just Joined!
- Join Date
- Sep 2010
- Posts
- 9
well. I have the following script. Somewhere there is something wrong:
Output from terminal:Code:#!/bin/sh for i in `cat userlist.txt ` do i="${i/ /}123" echo $i useradd -p password $i echo; echo "Username $username password changed" done
So it's making the user, but not with the password 123 but makes a user with 123 afther.Code:Linuxuser123 Username password changed
No errors, but i can't login.
??
- 09-07-2010 #10Just Joined!
- Join Date
- Sep 2010
- Posts
- 9
Allso, it's not making a homedir. I thought useradd -m (username) was for making a homedir?
if i do that, the error is that there is to many arguments


Reply With Quote
