aboutsummaryrefslogtreecommitdiff
path: root/sem7/dist/lec1/exc1.bash
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-09-23 15:22:01 +0200
committerJulian T <julian@jtle.dk>2021-09-23 15:22:01 +0200
commit9784dd520a72b775641d649153101f4672139a9e (patch)
treed8ee83ab263c8951c68f42ff8e48a08469576db9 /sem7/dist/lec1/exc1.bash
parentff954bdc2e33bfafbf8efac030762835583a3246 (diff)
Add assignments for dist 3
Diffstat (limited to 'sem7/dist/lec1/exc1.bash')
-rwxr-xr-xsem7/dist/lec1/exc1.bash26
1 files changed, 26 insertions, 0 deletions
diff --git a/sem7/dist/lec1/exc1.bash b/sem7/dist/lec1/exc1.bash
new file mode 100755
index 0000000..e777f17
--- /dev/null
+++ b/sem7/dist/lec1/exc1.bash
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+set -e
+
+if [ "$#" -lt 2 ]; then
+ echo Not enough arguments, use $0 inputfile outputfile
+ exit 1
+fi
+
+inputfile=$1
+
+if [[ ! -f "$inputfile" ]]; then
+ echo File $inputfile does not exist
+ exit 1
+fi
+
+outputfile=$2
+
+echo Sending file $inputfile into $outputfile
+
+# Open a server
+nc -l -p 8080 > $outputfile &
+
+# Connect with client and send file
+nc -c 127.0.0.1 8080 < $inputfile
+
+echo Done