From 2c3830d50dec0a41e4c76e0f1cdfaac0ce6d9b49 Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Sun, 29 Dec 2013 14:58:07 +0100 Subject: [PATCH] Exercise 6 and 7 done --- Labb8/loggedin.html | 23 ++++++++++++++++++++ Labb8/ovning6.sh | 16 ++++++++++++++ Labb8/ovning7.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 Labb8/loggedin.html create mode 100755 Labb8/ovning6.sh create mode 100755 Labb8/ovning7.sh diff --git a/Labb8/loggedin.html b/Labb8/loggedin.html new file mode 100644 index 0000000..a043e87 --- /dev/null +++ b/Labb8/loggedin.html @@ -0,0 +1,23 @@ +Logged in users + + + + + + + + + + + + + + + + + + + +
UserTTYDateTime
jaketty72013-12-0614:10
jakepts/02013-12-2608:56
jakepts/12013-12-0614:56
jakepts/22013-12-2914:21
jakepts/32013-12-2608:56
jakepts/52013-12-2717:58
jakepts/72013-12-2811:05
+ + diff --git a/Labb8/ovning6.sh b/Labb8/ovning6.sh new file mode 100755 index 0000000..8795a62 --- /dev/null +++ b/Labb8/ovning6.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Jack-Benny Persson +# LX13 +# Exercise 6 - lab 8 (Write a script with awk that prints linenumbers) + +# Sanity check +if [ $# -ne 1 ]; then + echo "$0 requiers one argument" + exit 1 +fi + +awk '{ print NR" " $0 }' "$1" + +exit 0 + diff --git a/Labb8/ovning7.sh b/Labb8/ovning7.sh new file mode 100755 index 0000000..513510b --- /dev/null +++ b/Labb8/ovning7.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Jack-Benny Persson +# LX13 +# Exercise 7 lab 8 (Write a script to show logged in users in a HTML table + +# Binaries +Awk="/usr/bin/awk" +Sed="/bin/sed" +Printf="/usr/bin/printf" +Who="/usr/bin/who" + +# Variables +Outfile="/home/jake/loggedin.html" + +# Sanity check +if [ ! -w `dirname $Outfile` ]; then + echo "Can't write to `dirname $Outfile`" + exit 1 +fi + +for Bin in $Awk $Sed $Printf $Who; do + if [ ! -x $Bin ]; then + echo "Can't execute $Bin" + exit 1 + fi +done + + +### Main ### +exec 1> $Outfile + +# Print the HTML header for us +$Printf "Logged in users\n" +$Printf "\n" +$Printf "\n" +$Printf "\n" +$Printf "\n" +$Printf "\n" + +# Print all the current logins for us in a nice table +$Who | \ +awk 'BEGIN { OFS="\n" } { print $1, $2, $3, $4 }' |\ +sed '/^[a-z]/s/^/\n" +$Printf "
UserTTYDate" +$Printf "Time
"; ORS="\n
/' | sed '/[0-9]$/s/$/<\/td>/' | sed '$d' + +# End the table and HTML +$Printf "
\n" +$Printf "\n" +$Printf "\n" + +exit 0