Linux Foundation Certified System Administrator
Linux Foundation Certified System Administrator
exit 0
- We check the script properties and make him executable using these commands:
ls –ls script2
chmod +x script
./script2
cat script – verify the conteud of the script without run it
01-03 Using Loops in Shell Scripts
- Different conditiuonal statements are available in Bash
- If…then..fi
- While..do..done
- Until…do…done
- Case…in…esac
- For…in…do…done
We using script3 and script10
Script3 make an argument and script 10 make an account down to warn you time is up for
something you forget or need to do
01-04 Lab. Writing Shell Scripts
- A customer exported a long list of LDAP user names.These usernames are stored in the
file ldapusers.In this file, ever user has a aname in the format
cn=lisa,dc=example,dc=com. Write a scipt that extract the username only (lisa) from all
of these lines and write those to a new file
- Based on this new file, create local user account on your Linux box
- Note:while testing, it is not a smart idea to create the user accounts direftly. Find a
solution that proves that the script works wthout polluting your system with many user
names.
01-05 Lab Solution. Writing Shell Scripts
Create and execute script lessons1.sh
#!/bin/bash
#extract the user names
for i in $(cat ldapusers)
do
USER=${i%%,*}
USER=${USER#*=}
echo $USER >> users
done
# show that user creation will work
for j in $(cat users)
do
echo useradd $j
done
~
~
Create ldapuser file
Ldapusers: cn=lisa,dc=example,dc=com
Cn=amy,dc=example,dc=com
02 Managing Local Security