Question
In Putty
1. Create Bash shell script that would let a user make a copy of all the files in a directory. (3 points) 2. Create two Bash
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the following shell scripts for the given question.

Steps for Program#1:

1.Read the source directory and destination directory.

2. then copy all the files from source directory to desitnaiton directory.

Steps for Program#2

Shell script# 1:

1. display username and current working directory

2. display usage of all the disks

Shell script# 2:

1. displays time of the host

2. displays list of users logged in

3. displays the uptime of a host

Steps for Program#3:

1. Use menu based approach for running the three scripts based on user's selection in this script.

Shell Script 1:

#!/bin/bash

source=
desti=
echo ""
echo ""
echo " This script is used to copy all the files from"
echo " source directory to destination directory."
echo ""
echo ""

#read the source dir
echo "Enter the source directory: "
read source

#check if the directory is present or not
if [ ! -d $source ]
then
echo "Source directory not found"
exit 1
fi

#read the destination dir
echo "Enter the destination directory: "
read desti

#check if the directory is present or not
if [ ! -d $destination ]
then
echo "Destination directory not found"
exit 1
fi

#copy all the files from source to destination
echo "copy is in progress..."
cp -p $source/* $desti/

#check if the copy is successful or not
if [ $? -eq 0 ]
then
echo "Files copied fine"
else
echo "Error in file copying"
fi

Shell script 2-a:

#!/bin/bash

echo "Current logged in user name is: $USERNAME"
echo " "
echo " "
echo "current working directory is: `pwd`"

echo " "
echo " "

echo "Following are the usage of disks in the host:"
echo " "
echo " "
#df command is to get the disk usage and free space
df

Shell Script 2-b:

#!/bin/bash

echo "Current time is: `date`"
echo ""
echo ""

echo "Following are the list of users logged in to the host:"
echo ""
who

echo ""
echo ""
echo "Uptime of the host is:"
echo " "
uptime

Shell script 3:

#!/bin/bash
input=

#specifies the path of the script1, script2 here,
#so that when we run it, it will take the right to execute

DIR="."

while [ true ]
do
#display user menus
echo " "
echo "1. Copy files"
echo "2. Disk usage founder"
echo "3. Time of a host"
echo "4. Exit"
echo ""

#read the user input
read input

#validate the read input with 1,2,3,4
if [ "$input" != "1" ] && [ "$input" != "2" ] && [ "$input" != "3" ] && [ "$input" != "4" ]
then
echo "Invalid input. exiting.."
exit 1
elif [ "$input" == "1" ]
then
#run scrip1
./$DIR/scrip1.sh
elif [ "$input" == "2" ]
then
#run scrip2_a.sh
./$DIR/scrip2_a.sh
elif [ "$input" == "3" ]
then
#run scrip2_b.sh
./$DIR/scrip2_b.sh
else
echo "Exiting.."
sleep 1
exit 0
fi

done

Output of the script3 run:

$ ./scrip3.sh

1. Copy files
2. Disk usage founder
3. Time of a host
4. Exit

1


This script is used to copy all the files from
source directory to destination directory.


Enter the source directory:
test1
Enter the destination directory:
test2
copy is in progress...
Files copied fine

1. Copy files
2. Disk usage founder
3. Time of a host
4. Exit

2
Current logged in user name is: GUHAN


current working directory is: /c/Users/GUHAN


Following are the usage of disks in the host:


Filesystem 1K-blocks Used Available Use% Mounted on
C:/Program Files/Git 104857596 68001460 36856136 65% /
D: 178257916 47322164 130935752 27% /d
E: 204244988 104517076 99727912 52% /e

1. Copy files
2. Disk usage founder
3. Time of a host
4. Exit

3
Current time is: Thu, Jul 30, 2020 6:52:31 AM


Following are the list of users logged in to the host:

radi            tty1        2020-03-16  19:27
tecnt       pts/0               2020-03-16      19:26   (192.168.56.1)
robt            pts/1           2020-03-16      19:27   (192.168.56.1)

Uptime of the host is:

00:10:18 up 122 days, 30 min, 2 users, load average: 0.22, 0.41, 0.32

1. Copy files
2. Disk usage founder
3. Time of a host
4. Exit

4
Exiting..

Script 1 screen shot:

#!/bin/bash source= desti= echo echo echo This script is used to copy all the files from source directory to destination d

Script 2a screen shot:

#!/bin/bash echo Current logged in user name is: $USERNAME echo - - echo echo current working directory is: pwd echo ech

Script 2b screen shot:

#!/bin/bash echo Current time is: date echo echo echo Following are the list of users logged in to the host: echo who e

Script 3 screen shot:

#!/bin/bash input= #specifies the path of the scriptı, script2 here, #so that when we run it, it will take the right to execu

Output:

$ ./scrip3.sh 1. copy files 2. Disk usage founder 3. Time of a host 4. Exit 1 This script is used to copy all the files from

radi ttyi 2020-03-16 19:27 tecnt pts/0 2020-03-16 19:26 (192.168.56.1) robt pts/1 2020-03-16 19:27 (192.168.56.1) Uptime of t

Add a comment
Know the answer?
Add Answer to:
In Putty 1. Create Bash shell script that would let a user make a copy of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a bash script that prompts a user with a menu of choices: Get the total...

    Write a bash script that prompts a user with a menu of choices: Get the total number of shell files from the current directory Get the total size of all the shell files from the current directory Get the total number of empty files in the system from the current directory Each option must be its own specific function. linux only

  • BCS 215 (Unix Operating Systems) Create a bash shell script that displays a coffee vending machine...

    BCS 215 (Unix Operating Systems) Create a bash shell script that displays a coffee vending machine menu and asks the user to make a choice - 1. Print "Please enter your choice: decaf|regular|latte|cappuccino" 2. Depending on the user input, print out the related price - decaf: 2 dollars regular: 2 dollars latte: 3 dollars cappuccino: 3 dollars For anything else, please display "Please make a valid choice." 3. Upon a successful execution of the script, display "Thank you for using...

  • Problem 1 Write a BASH script to create a user account from the Linux system on...

    Problem 1 Write a BASH script to create a user account from the Linux system on which your script is run. The script should process two positional parameters. First positional parameter is supposed to be a string with a user name (e.g., user_name) Second positional parameter is supposed to be a string with a user password (e.g., user_password) In your script: Check if two positional parameters were passed to your script when it was invoked If NOT, print an appropriate...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • ___________________ Create a shell script program that has displays the following menu on a page: This...

    ___________________ Create a shell script program that has displays the following menu on a page: This is a Linux Question, and the script is written in Vi test, and run in Putty. Press 1 to enter new order. Press 2 to access order status. Press 3 to cancel order. Paste a screenshot shot of the code below Paste a screenshot of the code output below (2 point):

  • using lubuntu ce the following activities on your Linux virtual machine. Then complete estions. Write a script file which when executed will perform the following: First display today's date in d...

    using lubuntu ce the following activities on your Linux virtual machine. Then complete estions. Write a script file which when executed will perform the following: First display today's date in dd.mm.YYYY format (e.g. 20.04.2019). Ask user to enter a name to create a directory. Create a directory by the given directory name above. . . Ask user to enter a name to create a file. Copy the file /etc/passwd to the given filename above inside the newly created directory Copy...

  • Write a bash shell script to carry out each of the following tasks: What to Do:...

    Write a bash shell script to carry out each of the following tasks: What to Do: a. Safe Delete: When you use the “rm” command in Linux, it will delete the specified files, with no chance for recovering them back later. Write a script (called srm) that will safely delete the files passed to it as command-line arguments. For example, typing the command: “srm file1 file2 file3”, the script shall not actually delete these files, but instead it shall move...

  • Hello, I am attempting to write a basic shell script using bash. It will need to...

    Hello, I am attempting to write a basic shell script using bash. It will need to print the user, host, time, and date. It will need to take user input for a txt file to be searched and create a new file to save the results. It must print the number of lines and characters in the text. The user will need to enter three words to be searched, and the number of occurrences of those words in the text...

  • SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5...

    SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT