Register
It is currently Mon Oct 20, 2014 11:20 pm

help me complete a script to create users from a file


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Mon Apr 23, 2012 5:53 pm   

Joined: Mon Apr 23, 2012 5:48 pm
Posts: 1
when i run the file i get errors from the fi on the second to last line
please help me debug this

# No arg passed.Display error message. stop processing
if [ -z "$1" ]
then
echo "Not a Valid command line argument"
exit 1
else
#otherwise create user names from file
#grep takes out all the comments
#sed removes the header
#cut gets the first letter of the first name
#results are stored in first_initial.txt
grep -v '#' $1 | sed 1d | cut -b 1 > first_initial.txt
#grep takes out all the comments
#sed removes the header
#awk for the last names
#results are stored in last_name.txt
grep -v '#' $1 | sed 1d | awk '{print line $2}' > last_name.txt
pr -m -t first_initial.txt last_name.txt | awk '{print $2 $1}' > user_names.txt

# store user names into a variable
names=`cat user_names.txt`
fi
# second parameter option -d Display user names and exit
if [ -n "$2" ]
then
echo "$names"
exit
else
#read users from file and create the accounts
for i in `more user_names.txt `
do
echo $i
useradd $i
fi
done


Top
 Profile  
 PostPosted: Mon Apr 30, 2012 9:51 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Looks like you're trying to end your IF loop before you're done with your FOR loop.
Try putting 'fi' AFTER 'done' :)


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP