Sponsored Content
Top Forums Shell Programming and Scripting Using multiple 'for' statements Post 303024414 by Scott on Monday 8th of October 2018 07:59:25 AM
Old 10-08-2018
There are a number of ways to accomplish that. Assuming there is a direct one-to-one mapping between the two input files, then you could do something like:
Code:
paste file[12] | while read user pass x; do
  useradd "$user"
  echo "$pass"| passwd --stdin "$user"
done

(not tested, and it would make sense to add some handling in case a user exists, etc. Additionally, should your usernames (heaven forbid!) or password have whitespaces, then you might need to use a delimeter with the paste command, and use IFS=... between the while and read (and remove x, which is only used to ensure any junk after pass is removed))

Last edited by Scott; 10-08-2018 at 09:11 AM.. Reason: Added quotes around variable usage
These 2 Users Gave Thanks to Scott For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

multiple conditions in if statements

Hi all, I'm confused about the proper syntax for multi-conditional if then statements. I'm trying to set limitations on info input on the command line.. i.e. if ] ;then $x=$vr1 else print "You have entered an invalid option." Can someone please clue me in on what is wrong with my syntax;... (3 Replies)
Discussion started by: tim mauger
3 Replies

2. Shell Programming and Scripting

multiple 'if' statements out of array

I want to do multiple comparisons on a series of numbers from an array: I send the numbers in file1 through want to print out some info from file2 based on some conditions. The syntax just isn't correct??? awk ' NR==FNR{ a=$0 next ... (2 Replies)
Discussion started by: dcfargo
2 Replies

3. Shell Programming and Scripting

How do I execute multiple statements within If then else

Please help me. I have been doing this for several hours. Here is the code if then echo a b c d >> file.txt echo 1111 >> file.txt fi The reason I want the two echo is because I want these statements printed on multiple lines. I keep getting error . First it tells me... (2 Replies)
Discussion started by: asemota
2 Replies

4. Shell Programming and Scripting

Running multiple if statements

Hi, Hav automated a process, and it is working fine. for first process alone status = ` ps -ef |grep a ` if then echo " Success" > temp/logfile else echo " Failure" > temp/logfile fi Now I hav to write script to automated some 2 process and then send mail using cron.. ... (5 Replies)
Discussion started by: NehaKrish
5 Replies

5. Shell Programming and Scripting

execute multiple statements in if-else

how can we execute multiple statements in else condition i have if then statement else statements fi in else condition i have multiple statements but it executing only one statement is there any way to execute multiple statements (4 Replies)
Discussion started by: nani1984
4 Replies

6. Shell Programming and Scripting

multiple echo statements in if condition

Hi , I have a peculiar problem. i have an if block like this if ; then echo " todays date is " ${date} >> log_file echo " file count is " $ count >> log_file mv filename1 filename 2 else echo "no files available ">> log_file fi the echo statement "no files available " is not... (2 Replies)
Discussion started by: wizardofoz
2 Replies

7. Shell Programming and Scripting

Multiple if Statements

Hi All, I need to check for 3 conditions and if all the 3 are not satified need to say that services are not running.... is the below code correct. #********** Check to see if Service 1 is still running************** if then echo "$datetimestamp: Service1 is not running" >>... (4 Replies)
Discussion started by: ch33ry
4 Replies

8. Shell Programming and Scripting

Multiple If statements in bash problem

Hi everyone, May you help me with the correct syntax of the follow bash statements please X=10 if ]; then echo "The value is between 1 and 5" for ((i=1;i<=${X})); do echo $i done else if ]; then echo "The value is between 6 and 10" for ((i=1;i<=${X})); do ... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

9. Shell Programming and Scripting

Multiple while statements?

I'm working on a script for class as a final project. We have to ask for values (city, state, zip) five times, but the state can only be MI, IN, IL, or OH. I'm trying to do this with a while loop inside of a while loop, but I have no idea how to do it properly. Here's what I have so far: ... (3 Replies)
Discussion started by: nickzourdos
3 Replies

10. UNIX for Dummies Questions & Answers

Multiple if statements

exmaple: file1 and file2 has 1 bit if then exit else send out email fi if then exit else send out email fi it exits the 1st if. did not continue with my 2nd if. thanks in advanced. Please use CODE tags are suggested on every page when you post an item in... (7 Replies)
Discussion started by: lawsongeek
7 Replies
cvsd-passwd(8)						      System Manager's Manual						    cvsd-passwd(8)

NAME
cvsd-passwd - generate password entries for repositories SYNOPSIS
cvsd-passwd REPOS [+|-]NAME... DESCRIPTION
cvsd-passwd adds, updates or deletes users from repository passwd files for use with cvsd. OPTIONS
REPOS Specify the directory in which the repository is located. This argument can be the top of the repository, the CVSROOT directory or even the passwd file in the CVSROOT directory. [+]USER[:SUSER] Add or update the user to the CVSROOT/passwd file. If the user does not exist a password for the user is asked and the user is added for use with cvsd. If the user already exists a password for is asked and the password field is modified. The :SUSER part can be user to change or set mapping to a system user. If you do not specify anything, a reasonable default is used based upon your cvsd configuration. If you don't want to map the user to any specified system user you can specify an empty SUSER and use 'USER:'. -USER Remove the user from the CVSROOT/passwd file. EXAMPLES
Add an anoncvs user to access the given repository: cvsd-passwd /var/lib/cvsd/myrepos +anoncvs If the user already exists, change the password. Remove a user from the repository passwd list: cvsd-passwd /var/lib/cvsd/myrepos -foo Add a user and specify that cvs should remap this user to the joe system user: cvsd-passwd /var/lib/cvsd/myrepos joecvs:joe Note that the user joe should be known in the system passwd file and that cvsd should be run as root or user joe for this to work. SEE ALSO
cvsd(8) AUTHOR
Arthur de Jong <arthur@arthurdejong.org>. Version 1.0.24 Jun 2012 cvsd-passwd(8)
All times are GMT -4. The time now is 02:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy