after class fixes
This commit is contained in:
		
							parent
							
								
									c35934b33b
								
							
						
					
					
						commit
						f7e19ebc11
					
				| 
						 | 
				
			
			@ -69,6 +69,14 @@ Now we have all the usernames we need and we can save this to a file by redirect
 | 
			
		|||
cat accounts.csv | cut -d "," -f 4 | tail -n +2 | cut -d ":" -f 1 | cut -d "@" -f 2 > usernames.list
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Vladimir pointed out a handy way to replace the `tail` command with a `grep`.
 | 
			
		||||
It's less cryptic and would go as follows.
 | 
			
		||||
The result is the same but the way we get there is slightly different.
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
cat accounts.csv | grep "@" | cut -d "," -f 4 | cut -d ":" -f 1 | cut -d "@" -f 2
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### The $PASSWORD
 | 
			
		||||
 | 
			
		||||
To extract the password we need to combine two field from the CSV file.
 | 
			
		||||
| 
						 | 
				
			
			@ -80,6 +88,14 @@ Don't forget the man pages!
 | 
			
		|||
cat accounts.csv | awk -F "," '{print $2 $3}' | tail -n +2
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Sarah found an interesting feature to `cut` where you can show multiple fields at the same time.
 | 
			
		||||
The syntax is quite easy but it introduces a `,` we'll have to get rid of afterwards.
 | 
			
		||||
Combined with Vladimir's approach this gives a more comprehensible command.
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
cat accounts.csv | grep "@" | cut -d "," -f 3,2 | tr -d ","
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
If you feel like making the password complexer, you can try to add in extra data into the `awk` command, or even append random numbers to the end.
 | 
			
		||||
How would you do this?
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -109,8 +125,6 @@ Last but not least, don't forget to add execution permissions to this script wit
 | 
			
		|||
```bash
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
LINE=$1
 | 
			
		||||
 | 
			
		||||
head -$1 usernames.list | tail -1
 | 
			
		||||
head -$1 passwords.list | tail -1
 | 
			
		||||
head -$1 groups.list | tail -1
 | 
			
		||||
| 
						 | 
				
			
			@ -144,8 +158,6 @@ At the last line we *use* the variables to create a message we display on our ST
 | 
			
		|||
```bash
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
LINE=$1
 | 
			
		||||
 | 
			
		||||
USERNAME=$(head -$1 usernames.list | tail -1)
 | 
			
		||||
PASSWORD=$(head -$1 passwords.list | tail -1)
 | 
			
		||||
GROUP=$(head -$1 groups.list | tail -1)
 | 
			
		||||
| 
						 | 
				
			
			@ -164,8 +176,6 @@ This gives us the following script.
 | 
			
		|||
```bash
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
LINE=$1
 | 
			
		||||
 | 
			
		||||
USERNAME=$(head -$1 usernames.list | tail -1)
 | 
			
		||||
PASSWORD=$(head -$1 passwords.list | tail -1)
 | 
			
		||||
GROUP=$(head -$1 groups.list | tail -1)
 | 
			
		||||
| 
						 | 
				
			
			@ -186,8 +196,6 @@ Nice!
 | 
			
		|||
```bash 
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
LINE=$1
 | 
			
		||||
 | 
			
		||||
USERNAME=$(head -$1 usernames.list | tail -1)
 | 
			
		||||
PASSWORD=$(head -$1 passwords.list | tail -1)
 | 
			
		||||
GROUP=$(head -$1 groups.list | tail -1)
 | 
			
		||||
| 
						 | 
				
			
			@ -210,8 +218,6 @@ We probably want to use `/bin/bash` for this option!
 | 
			
		|||
```bash 
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
LINE=$1
 | 
			
		||||
 | 
			
		||||
USERNAME=$(head -$1 usernames.list | tail -1)
 | 
			
		||||
PASSWORD=$(head -$1 passwords.list | tail -1)
 | 
			
		||||
GROUP=$(head -$1 groups.list | tail -1)
 | 
			
		||||
| 
						 | 
				
			
			@ -224,8 +230,6 @@ useradd $USERNAME -m -G $GROUP -s "/bin/bash"
 | 
			
		|||
 | 
			
		||||
echo "setting password: $PASSWORD for $USERNAME"
 | 
			
		||||
echo $USERNAME:$PASSWORD | chpasswd
 | 
			
		||||
 | 
			
		||||
echo "adding $USERNAME to $GROUP"
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
This is getting pretty close to perfect!
 | 
			
		||||
| 
						 | 
				
			
			@ -249,7 +253,6 @@ Don't worry if this looks to complicated at the moment, we'll do this exercise a
 | 
			
		|||
```bash
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
FILE=$1
 | 
			
		||||
LINES=$(cat $1)
 | 
			
		||||
 | 
			
		||||
for LINE in $LINES;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue