This assignment will assess your ability to write bash scripts.
Example output for your reference:
The script should have the following output when run with 0 or 2+ arguments:
# /root/exam02.sh
Exiting!
# echo ${?}
40
# /root/exam02.sh testarg1 testarg2
Exiting!
# echo ${?}
40
The script should have the following output when run with exactly 1 argument:
# /root/exam02.sh testarg1
Arg1: testarg1
HomeworkLib@Chegg-PC:~$ sudo su
[sudo] password for HomeworkLib:
root@Chegg-PC:/home/HomeworkLib# cd
root@Chegg-PC:~# pwd
/root
root@Chegg-PC:~# vi /root/exam01.sh
~
~
"~/exam02.sh" 1 line, 1 character
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Exiting!"
exit 40
elif [ $# -eq 1 ]
then
echo "Arg1:" $1
fi
root@Chegg-PC:~# sh
/root/exam02.sh
Exiting!
root@Chegg-PC:~# echo $?
40
root@Chegg-PC:~# sh
/root/exam02.sh testarg1 testarg2
Exiting!
root@Chegg-PC:~# echo $?
40
root@Chegg-PC:~# sh
/root/exam02.sh testarg1
Arg1: testarg1
This assignment will assess your ability to write bash scripts. Drop down to the root user...
1. Write 4 simple shell scripts. Each question will ask you to write one or more command lines to solve a problem. Put the command(s) from each problem into a file named problem1.sh, problem2.sh Note that if you want your script to be interpreted by bash, each file should start with the line: #!/bin/bash and will have one (or more, as needed) commands following it. To execute each script in bash, so you can determine if it is working or...
Programs/scripts 13. Write a bash shell script that displays the date by using the shell command date. 14. Write a command line program that takes a number and a command as arguments. Call that command that number of times. For example, if your program name is "test" test 3 dir <shows directory> dir <shows directory> dir <shows directory>
PYTHON
4. While Loops (25%) You will be writing a "shell" application, it will be on a loop, taking in commands from the user. The command syntax is as follows command> <arga» <arg1> arg n> The commands you are to implement: Command Description Prints all arguments on the same line, with a space between each. Treats all arguments as floating-point numbers, and prints the average. MUST print an error if given invalid arguments Finds the index of arg1 in arg0....
1.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script. Do not count recursively in subdirectories. Do not call any external Linux utilities such as “ls”. 2.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script....
In Bash Write two scripts, 'backup.sh' and 'restore.sh' which do the following: backup.sh accepts a list of arguments which indicate the name o the output file and a list of files that should be backed up. Will take all of the files provided oher than the first and create a tar-ball(a tarred, gzipped file) with the name provided in the first argument. restore.sh Accepts a single filename of a tar-ball created by the script above and restores the files from...
How to write a bash shell script that prints a hollow box after user enters number of lines, ie "bash hbox 4" , prints: **** * * * * **** My code doesnt work. i need it to take in the argument from the command line: ./hbox 4 "*" echo "Enter number of rows" read sz clear for (( x = 1; x <= $sz; x++ )); do for (( y = 1; y <= $sz; y++ )); do...
write the bash script Write a script compress_large_files.sh. This script accepts one or more command line arguments. The first argument has to be an integer; let’s call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the...
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...
Write a bash shell script called direct.sh. This script will take an arbitrary number of command line arguments. Your script should create directories starting with the first argument, then the second directory inside the first one, and then the next one inside the second one, and so on.