In: Computer Science
Write a bash script that...
A bare bone bash script to solve the given problem is copied below. Do note that it doesn't implement checks for given command line arguments neither does it checks whether a task is successful or failed as its not the requirement of the problem but it does issues commands that will display the change once its done.
To summarize, the commands used for different actions are:
Also note that you would need to execute the script as root or privileged user or with sudo to allow it carry out most of the actions.
=============================================================================
#!/bin/bash
key="${1}"
case ${key} in
user)
echo "Create new user"
echo "==============="
echo -n "Specify username: "
read username
echo -n "Specify user ID: "
read userid
useradd -u $userid $username
id $username
;;
printer)
echo "Add new printer"
echo "==============="
echo -n "Specify printer name: "
read printername
echo -n "Specify printer IP: "
read printerip
lpadmin -p $printername -v
socket://$printerip:9100
lpstat -p $printername
;;
permissions)
echo "Set permission"
echo "=============="
echo -n "Specify document path: "
read docpath
echo -n "Specify the permission to set: "
read perm
chmod $perm $docpath
ls -l $docpath
;;
restart)
echo "Restarting the computer..."
echo "=========================="
echo
shutdown -r now
;;
esac
=============================================================================
Here's the script screenshot:
=============================================================================
Here's a sample run of the script for each possible scenario: