Final Exam review exercises#
1. Shell scripts#
Below are two shell scripts. Script
send.sh
#!/bin/bash
ipaddr='192.168.122.11'
port='9092'
echo "provide input file name"
read fname
/bin/cat "$fname" | /bin/netcat -N "$ipaddr" $port
and script receive.sh:
#!/bin/bash
DIR='/home/hostadm'
fname='fileget.out'
port='9092'
if [ -s "$DIR/$fname" ]
then
echo 'file exists'
else
/bin/netcat -N -l "$port" > "$DIR/$fname"
fi
A) What do the scripts do?
B) Create a new VM. Put script receive.sh on the VM. Put script send.sh on the desktop, and modify variable ipaddr in the script to match the IP address of the VM. Run both the scripts to send/receive a file between the desktop and the VM.
3. Shell scripting#
Consider the following script:
#!/bin/bash
cmmd= /usr/bin/md5sum
for i in $(ls /etc); do
if [ ! -d /etc/$i ] then
$cmmd /etc/$i
fi
done
It fails to run due to a few syntactic errors.
A) Find the errors in the script.
B) Explain what the script does.
4. Task scheduling#
A) Schedule the script to run once on July 9 at 11 pm.
B) Schedule the script to run every Wednesday at 10:15 AM.
6. Compilation and Makefiles#
Download tar archive http://capone.rutgers.edu/coursefiles/matrix_gsl.tar and untar it.
A) Compile each of the files: matrix_show.c, matrix_view.c, matrix_write.c
, and run the executables.
B) Develop a Makefile with the targets to compile each of the files.
C) Install make and run it for the targets.
7. Python scripting#
Start jupyter notebook in directory Python.
The tasks below, should be completed within jupyter notebook:
A) Create nested directory tree DIR1/DIR2/DIR3
B) Write words ‘task1’, ‘task2’, ‘task3’, and ‘task4’, each in new line, into file output.txt
in directory DIR1/DIR2/DIR3
8. Python scripting#
A) Write a python script to find all files with extension .script
in directory /usr.
B) Modify the script to provide the searchable filename as an argument. Run the scipt to find files with extensions .script
, then .conf