Exercise 6 and 7 done
This commit is contained in:
23
Labb8/loggedin.html
Normal file
23
Labb8/loggedin.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<html><head><title>Logged in users</title></head>
|
||||
<body>
|
||||
<table border=1>
|
||||
<tr>
|
||||
<td><b>User</b></td><td><b>TTY</b></td><td><b>Date</b></td><td><b>Time<b></td>
|
||||
</tr>
|
||||
<td>jake</td><td>tty7</td><td>2013-12-06</td><td>14:10</td>
|
||||
</tr><tr>
|
||||
<td>jake</td><td>pts/0</td><td>2013-12-26</td><td>08:56</td>
|
||||
</tr><tr>
|
||||
<td>jake</td><td>pts/1</td><td>2013-12-06</td><td>14:56</td>
|
||||
</tr><tr>
|
||||
<td>jake</td><td>pts/2</td><td>2013-12-29</td><td>14:21</td>
|
||||
</tr><tr>
|
||||
<td>jake</td><td>pts/3</td><td>2013-12-26</td><td>08:56</td>
|
||||
</tr><tr>
|
||||
<td>jake</td><td>pts/5</td><td>2013-12-27</td><td>17:58</td>
|
||||
</tr><tr>
|
||||
<td>jake</td><td>pts/7</td><td>2013-12-28</td><td>11:05</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
16
Labb8/ovning6.sh
Executable file
16
Labb8/ovning6.sh
Executable file
@@ -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
|
||||
|
53
Labb8/ovning7.sh
Executable file
53
Labb8/ovning7.sh
Executable file
@@ -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 "<html><head><title>Logged in users</title></head>\n"
|
||||
$Printf "<body>\n"
|
||||
$Printf "<table border=1>\n"
|
||||
$Printf "<tr>\n"
|
||||
$Printf "<td><b>User</b></td><td><b>TTY</b></td><td><b>Date</b>"
|
||||
$Printf "</td><td><b>Time<b></td>\n"
|
||||
$Printf "</tr>\n"
|
||||
|
||||
# Print all the current logins for us in a nice table
|
||||
$Who | \
|
||||
awk 'BEGIN { OFS="</td><td>"; ORS="\n</tr><tr>\n" } { print $1, $2, $3, $4 }' |\
|
||||
sed '/^[a-z]/s/^/<td>/' | sed '/[0-9]$/s/$/<\/td>/' | sed '$d'
|
||||
|
||||
# End the table and HTML
|
||||
$Printf "</tr>\n"
|
||||
$Printf "</table>\n"
|
||||
$Printf "</body>\n"
|
||||
$Printf "</html>\n"
|
||||
|
||||
exit 0
|
Reference in New Issue
Block a user