Question

In: Computer Science

Write a bash script that... create new user ./finalProject user if a new user is to...

Write a bash script that...

  • create new user
    • ./finalProject user
    • if a new user is to be created ask for the new users information and use it when creating the new user
  • add a new printer
    • ./finalProject printer
    • ask anything you need in order to create the new printer (I.e. name)
  • permissions
    • ./finalProject permissions
    • ask what document and permissions the user wants
  • restarting the computer
    • ./finalProject restart

Solutions

Expert Solution

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:

  1. Create user - useradd -u <USER_ID> <USER_NAME>
  2. Add printer - lpadmin -p <PRINTER_NAME> -v <PRINTER_URI>
  3. Set permission - chmod <PERMISSIONS> <DOCUMENT_PATH>
  4. Restart computer - shutdown -r now

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:


Related Solutions

Write a short bash script that takes in two arguments from a user, asks the user...
Write a short bash script that takes in two arguments from a user, asks the user whether they would like to add, subtract, multiply, or divide. Each of these operations must be a function that returns data.
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the...
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result. Submit your program as LastName_FirstName.sh file.
Write a Powershell script to create a Windows user account that is a non-admin user. This...
Write a Powershell script to create a Windows user account that is a non-admin user. This assignment assumes that you already have a Windows VM, with the administrator account created.. To complete the assignment, write the PowerShell script, run it on your VM, and submit the script here.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Fully Functional Script written in BASH In this section, you will write a fully functional script...
Fully Functional Script written in BASH In this section, you will write a fully functional script to help your manager with an important project that will build upon what you learned from your script work in Milestone Four. After you have written the script, you will execute it to generate a report for all three users (once for Bob, once for Henry, and once for Frank). You should have three unique generated reports in your ~/scripts directory (or more if...
Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on...
Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on the command line 2. For each file name provided, delete any line that contains the string: qwe.rty When the changes are completed, the script should display the total number of files scanned, and the total number of files changed. Example Command: assessment-script-a file.a file.b file.c file.d file.e    Example Output: 5 files scanned, 3 files changed 3. Your script should include a series of...
creating a bash script called guessingGame.sh The guessingGame.sh should generate a random number that the user...
creating a bash script called guessingGame.sh The guessingGame.sh should generate a random number that the user has to guess. Each time after a guess input the program will let the user know if their guess is too high or too low until they guess the right number. The script should keep a count of how many guesses have currently been made. If the user the has made five guesses without guessing correctly the program should give a hint and let...
create an executable bash runtests.sh as follows: The script must include the definition of a recursive...
create an executable bash runtests.sh as follows: The script must include the definition of a recursive function, explore The script prompts the user to enter a directory name and an executable name, and checks that they are both readable and executable (terminating with an error message if not). It then passes the two names to the explore function. The explore function carries out a recursive traversal of the directory and all its subdirectories, and runs the executable on each of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT