jbomb-automate #4
52
jconf
52
jconf
@@ -42,14 +42,60 @@ fi
|
|||||||
cmd=$1
|
cmd=$1
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
adduser)
|
adduser)
|
||||||
echo
|
|
||||||
|
exist=$(awk -F: -v username="$2" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd)
|
||||||
|
if [ "$exist" -eq 1 ]; then
|
||||||
|
echo "$2 user already exists"
|
||||||
|
else
|
||||||
|
# Source - https://stackoverflow.com/a
|
||||||
|
# Posted by Myrddin Emrys, modified by community. See post 'Timeline' for change history
|
||||||
|
# Retrieved 2026-01-01, License - CC BY-SA 4.0
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p "Do you want to create an user account $2 [Y/n]:" yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* )
|
||||||
|
useradd $2;
|
||||||
|
echo "Enter the password for $2:";
|
||||||
|
passwd $2
|
||||||
|
echo "$2 user account created successfully";
|
||||||
|
break;;
|
||||||
|
[Nn]* ) exit 1;;
|
||||||
|
* ) echo "Please answer yes or no.";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
deluser)
|
deluser)
|
||||||
echo
|
|
||||||
|
exist=$(awk -F: -v username="$2" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd)
|
||||||
|
if [ "$exist" -eq 0 ]; then
|
||||||
|
echo "$2 user doesn't exist"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p "Do you want to delete $2 user account? [Y/n]:" yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* )
|
||||||
|
userdel -rRZ $2;
|
||||||
|
echo "$2 user account deleted successfully";
|
||||||
|
break;;
|
||||||
|
[Nn]* ) exit 1;;
|
||||||
|
* ) echo "Please answer yes or no.";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
listusers)
|
listusers)
|
||||||
echo
|
husers= awk -F: '{ if ($3 >= 1000 && $1 != "nobody" ) {print $1}}' /etc/passwd
|
||||||
|
echo $husers
|
||||||
;;
|
;;
|
||||||
|
|
||||||
start)
|
start)
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user