Shell scripting exercises.#

netcat server and client.#

  • 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
#!/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.

Looking for files in a deb package by using command grep.#

  • Install package libgpg-error-dev on your desktop.

  • What are the file names that in the package that have extensions .a, .so, and .h?

  • Specify the commands you used to find the file names.

Shell script with errors.#

  • 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.

String replacement by using command sed and regular expressions.#

Download a tar ball archive from http://linuxcourse.rutgers.edu/summer2023/html/Final/linpack_bench.tgz

Extract the archive.

Create a shell script, replace.sh,

A) to replace value of N 1000 by N 200 in file linpack_bench.c.

Hint: use command sed to replace text patern define N followed by any integer number.

B) Modify the script to read the new value of N from the keyboard input.