LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2010, 07:47 PM   #1
c_tr13
LQ Newbie
 
Registered: Oct 2010
Posts: 2

Rep: Reputation: Disabled
expect script help


im trying to use a for loop inside an expect script. the objectve of the script is to add a user with password but i need to use a certain file of names to do so. The file consists of 100 names first and last.

Code:
#!/bin/bash

if [$# -ne 4]; then 
     echo "Usage: Username group Firstname lastname";
     exit;
fi

user = ${1};
gid = ${2};
fname = ${3};
lname = ${4};

useradd -c "$fname $lname" -g $gid $user;
is there any way to make a for loop to use a certain file of names so fname and lname are taken from the file and it would just go down the list? (this is just a section of my code and i want to eventually do this for group and user but i just wanted to start small)
 
Old 10-18-2010, 11:49 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
hi, welcome to LQ!

Why do you need expect for this task? Just use chpasswd.


Cheers,
Tink
 
Old 10-19-2010, 11:40 AM   #3
c_tr13
LQ Newbie
 
Registered: Oct 2010
Posts: 2

Original Poster
Rep: Reputation: Disabled
That would add 100 new specific users with just running the executable file?
 
Old 10-19-2010, 11:43 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
No. But you could make it a two-step process; create
user, change password - within one loop. No need to
use expect.

[edit]
I *assume* you're using expect for passwords?
If you just want to add users there's absolutely
no need to use expect at all...
[/edit]

Cheers,
Tink

Last edited by Tinkster; 10-19-2010 at 11:45 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-27-2010 11:27 PM
expect script sivga1 Programming 2 02-26-2010 01:36 PM
is it possible in expect script packets Programming 2 12-14-2009 08:01 PM
Expect Script coolest Programming 7 02-16-2009 03:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration