有没有办法在我选择任务后自动创建用户、删除用户、创建组和删除组?另外,为什么在选择要执行的任务后我无法执行任何这些任务,但在选择任务时却提示我输入您的选择?
#!/bin/bash
while true
do
clear
echo "========================="
echo "Menu ---"
echo "========================="
echo "Enter 1 to Create Group 1: "
echo "Enter 2 to Remove Group 2: "
echo "Enter 3 to Create User 3: "
echo "Enter 4 to Remove User 4: "
echo "Enter q to exit the menu q: "
echo -e "\n"
echo -e "Enter Your selection \c"
read answer
case "$answer" in
1) groupadd ;;
2) groupdel ;;
3) useradd ;;
4) userdel ;;
q) exit ;;
esac
echo -e "Enter return to continue \c"
read input
done
答案1
您必须添加您的用户或组的名称:
useradd Krup
groupadd KrupGroup
删除也一样
所以你的脚本将是这样的:
#!/bin/bash
while true
do
clear
echo "========================="
echo "Menu ---"
echo "========================="
echo "Enter 1 to Create Group 1: "
echo "Enter 2 to Remove Group 2: "
echo "Enter 3 to Create User 3: "
echo "Enter 4 to Remove User 4: "
echo "Enter q to exit the menu q: "
echo -e "\n"
echo -e "Enter Your selection \c"
read answer
case "$answer" in
1) echo "enter Group name to add"; read group ;groupadd $group ;;
2) echo "enter Group name to delete"; read group ;groupdel $group ;;
3) echo "enter User name to add"; read user ;useradd $user ;;
4) echo "enter User name to delete"; read user ; userdel $user ;;
q) exit ;;
esac
echo -e "Enter return to continue \c"
read input
done