Shell scripts create users in bulk and randomly generate passwords
Requirements: Batch creation of 10 system account OLDBOY01-OLDBOY10, and set the generated password (password is different).
Implementation script:
#!/bin/bash
#Question3
For I in $ (seq-w 10)
Do
Useradd-s/bin/bash oldboy$i
echo "Password$i" | md5sum | Tee-a Passwd.txt | passwd--stdin oldboy$i
Done
Requirement 2: Batch Create 10 System account OLDBOY01-OLDBOY10, and randomly set the password (password is 8 characters).
Slightly modified based on the script above:
#!/bin/bash
#Question4
For I in $ (seq-w 10)
Do
Useradd-s/bin/bash oldboy$i
echo "Password$i" | Md5sum |cut-c-8 | Tee-a Passwd.txt | passwd--stdin oldboy$i
Done
Bulk delete the user you just created:
#!/bin/bash
For I in $ (seq-w 10)
Do
Useradd-s/bin/bash oldboy$i
echo "Password$i" | md5sum | Tee-a Passwd.txt | passwd--stdin oldboy$i
Done
Randomly generated password script:
#!/bin/bash
#Question4
For I in $ (seq-w 10)
Do
Useradd-s/bin/bash oldboy$i
echo "$RANDOM" | Md5sum |cut-c-8 | Tee Passwd.txt | passwd--stdin oldboy$i
Done
Requirement 1: Use a For loop to create 10 files in the/root/scripts/practice/q1/oldboy directory. The name is:
Oldboy-1,
Oldboy-2,
.....
Oldboy-10.
Script implementation:
#!/bin/bash
#Question1
Shopt-s expand_aliases
Alias ll= "Ls-l"
Cd/root/scripts/practice/q1
#首先判断目录是否存在, does not exist the directory is created
if [!-e Oldboy]
Then
/bin/mkdir Oldboy
Else
echo ""
Fi
Path=/root/scripts/practice/q1/oldboy
CD $path
For ((i=1;i<=10;i++))
Do
/bin/touch oldboy-$i
Done
ll $path
Requirement 2: All oldboy-files created by the appeal are modified to linux-in bulk using the For loop.
Script implementation:
#!/bin/bash
#Question2
Shopt-s expand_aliases
Alias Ll= ' Ls-l '
Path=/root/scripts/practice/q1/oldboy
CD $path
For ((i=1;i<=10;i++))
Do
/BIN/MV oldboy-$i linux-$i
Done
ll $path
Requirement: Write a script to determine the IP address of all activities within a network.
Implementation script:
#!/bin/bash
#script_name: ipscan.sh
File1=/root/scripts/uplist
File2=/root/scripts/downlist
If [-e $file 1]
Then
RM-RF $file 1
Fi
If [-e $file 2]
Then
RM-RF $file 2
Fi
For ((i=2;i<=254;i++))
Do
/bin/ping-c 1 192.168.3. $i >>/dev/null
If [$?-eq 0]
Then
echo "192.168.3. $i is Alive" >>/root/scripts/uplist
Else
echo "192.168.3. $i is not alive" >>/root/scripts/downlist
Fi
Done
Bulk delete the user you just created:
#!/bin/bash
#del_user. Sh
For I seq -w 10
in
Do
Userdel-r oldboy$i
Done
Randomly generated password script:
#!/bin/bash
#Question4
For I in $ (seq-w 10)
Do
Useradd-s/bin/bash oldboy$i
echo "$RANDOM" | Md5sum |cut-c-8 | Tee Passwd.txt | passwd--stdin oldboy$i
Done
Shell scripts create users in bulk and randomly generate passwords