Part 1:
Create a shell script that returns a full name associated with a userid specified in the command line argument.
• Use the names found in /acct/common/CSCE215-Spring19.
• Your shell script should be named “findName.sh”
– Example usage:
$ ./findName.sh seiei
SETSUNA F SEIEI
$
– Your shell script must either:
Return the full name associated with the userid
or
Return an error message if the command line arguments are not equal to 1.
or
Return the message “Sorry that person is not in CSCE215 this semester” No other
output is acceptable.
Part 2: findName program (8 points)
1. Create a C++ program that takes a command line argument value (userid) and passes this argument
to a shell script. HINT: system()
2. As in the previous assignment, modify your makefile to include a rule that creates a backup of
the source files, makefile, and readme in an archive directory in your home directory structure. Submit
an uncompressed tar file named $USER.findname.tar with your modified source code files only. (ie
yourUserid.findname.tar)
Be sure to document your code in a README file.
• In order to obtain credit for your project your submission must react properly to the following
commands:
$ tar xvf $USER.findname.tar
$ make
$ ./findName someuserid
$
3. Your program will be graded based on it’s ability to execute the above commands and return one of 3
allowable outputs:
• first lastname, or
• some error message based on an incorrect number of command line arguments, or
• the message stating that the user is not in CSCE215 this semester
Part-1 Solution:
Filename: findname.sh
#!/bin/bash
# findName.sh
searchFile="/acct/commmon/CSCE215-Spring19"
if [[ $1 = "" ]] ; then
echo "You need to supply an argument to the script. Please rerun the script. syntax is below."
echo "./`basename $0` SETSUNA F SEIEI"
exit 2
fi
grep -i $1 ${searchFile}
if [[ $? = "1" ]] ; then
echo "$1 was not found in ${searchFile}"
fi
---------------------------------------------------------------------------------------------------------------
The above shell script returns a full name associated with a userid specified in the command line argument.
Part 1: Create a shell script that returns a full name associated with a userid specified...
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...
UNIX shell script that will create a backup of the file specified as an argument. This backup file will be saved in ~/backups/ with -date appended to the original file name. the date shall be in the form yymmdd:HHmm. Your script should check to make sure the ~/backups/ directory exists before copying files, creating the directory if necessary. Ensure your script will properly accept a file argument with path information and strip any path information prior to copying the file....
Write a script using simple shell commands. The script takes a command line argument that specifies a directory dir. The script first changes directory to dir, then prints the following in sequence: (a) A line starting “Current date and time: ”. Then on the same line, the current time and date. (b) A line starting “Current directory is : ”. Then, on the same line, the absolute pathname of the current working directory. (c) An empty line (d) The line...
Write a shell script called GetMyStuff.sh that will provide the above information (the script must be a executable, and must work regardless of which directory it is in). Also, just saying cat MyStuff.txt is not sufficient. (1.0%) A pipeline is the combination of at least 2 commands, where the output of command1 is the input for command2. The syntax is command1 | command2 where | is the pipeline operator. Read the man pages about the ls and wc commands. Devise...
Write a bash shell script, deleteFilesWithZeroLength.sh, that removes all zero length ordinary files in the directory passed as an optional argument. If you do not specify the directory argument, the script uses the present working directory as the default argument. Do appropriate exception handling in your script such as:If the arguments are more than 1, print out “Too many arguments passed”.If the argument passed is a regular file, print out “XXX is regular file”.1c. If the directory doesn’t exist, print out “Directory...
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>
In this exercise, you will create a script called file_ops.sh that uses the various file operators The file_ops.sh script will Use one command line argument Use four IF THEN statement to compare the first command line argument Determine which file operators to use that produces the following output when the script run with the arguments shown WARNING: In the IF THEN statements, to avoid syntax error messages, there must be a space before and after each bracket and also between...
Homework No.2 CSC 222 Write a shell script program called "countf.sh" that will count how many files or directories recursively. beside the file counts, also report how many files for each types (directory or regular files). It will either take arguments for specific directories and no argument. If no argument, it will read the current working directory as the starting point. Please also provide -h option to print out how to use your countf.sh program % ./countf.sh % ./countf.sh file1...
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.
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...