Linux CentOS 7 - Basic scripting
Configure a bash script called foo.sh; this script reads an input parameter: if the input is "A", it returns "B"; if the input is "B", it returns "A"; otherwise it shows the message "usage foo.sh A|B"On system1
Edit the file:# vim /root/foo.sh
#!/bin/bash
if
[ "$1" == "A" ]; then
echo
"B"
elif
[ "$1" == "B" ]; then
echo
"A"
else
echo
"/root/foo.sh A|B"
fi
Change the permissions to make it executable by all;
# chmod a+x foo.sh
Test it:
# ./foo.sh A
# ./foo.sh A
B
Configure a script called makeusers.sh which reads a list of users from a file and creates those users with the /bin/false shell;
On system 1
Edit the script
vim makeusers.sh
#!/bin/bash
if [ $# = 0 ]; then
echo "usage makeusers.sh <users file>"
exit 1
elif [ -f $1 ]; then
for i in `cat $1`; do useradd $i -s /bin/false; done
exit 0
else echo "file not found"
fi
Change the permissions of the script
chmod a+x makeusers.txt
Edit the users file list
vim users.txt
ramu
tom
ben
sam
lory
natasha
Test the script
./makeusers.sh users.txt
Verify it has worked propoerly:
cat /etc/passwd
Configure a script called makeusers.sh which reads a list of users from a file and creates those users with the /bin/false shell;
On system 1
Edit the script
vim makeusers.sh
#!/bin/bash
if [ $# = 0 ]; then
echo "usage makeusers.sh <users file>"
exit 1
elif [ -f $1 ]; then
for i in `cat $1`; do useradd $i -s /bin/false; done
exit 0
else echo "file not found"
fi
Change the permissions of the script
chmod a+x makeusers.txt
Edit the users file listvim users.txt
ramu
tom
ben
sam
lory
natasha
Test the script
./makeusers.sh users.txt
Verify it has worked propoerly:
cat /etc/passwd
Commenti
Posta un commento