Skip to content

Commit df1f476

Browse files
committed
Update cloud server check script
1 parent f1abda9 commit df1f476

File tree

3 files changed

+37
-35
lines changed

3 files changed

+37
-35
lines changed

NOTES.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Notes
22

3-
## Check a student's EC2 virtual machine
3+
## Check a student's cloud server
44

55
This requires netcat to be installed locally and on the server. Install it with
66
`brew install netcat` on macOS with [Homebrew](https://brew.sh).
@@ -11,8 +11,8 @@ ports that are supposed to be open. Those processes echo `OK` once as soon as a
1111
client connects.
1212

1313
Local netcat commands are then run to connect to each port and verify that the
14-
`OK` is received. This shows that the AWS firewall was correctly configured to
15-
open these ports.
14+
`OK` is received. This shows that the firewall was correctly configured to open
15+
these ports.
1616

1717
The `listen-server-ports.sh` script is then killed and deleted from the server.
1818

@@ -24,7 +24,7 @@ The `hostname` and the contents of the `/etc/hostname` files are also displayed
2424
for validation.
2525

2626
```bash
27-
$> ./scripts/check-aws-instance.sh 1.2.3.4
27+
$> ./scripts/check-student-server.sh 1.2.3.4 admin_user
2828
```
2929

3030
> Note: each `nc` command must be stopped by typing `Ctrl-C` **once** after the

scripts/check-aws-instance.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

scripts/check-student-server.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
fail() {
3+
>&2 echo "$@"
4+
exit 1
5+
}
6+
7+
STUDENT_IP="$1"
8+
STUDENT_USER="$2"
9+
test -n "$STUDENT_IP" || fail "The IP address of the machine to check must be provided to this script as the first argument"
10+
test -n "$STUDENT_USER" || fail "The username of the account to connect as must be provided to this script as the second argument"
11+
12+
scp -i id_rsa scripts/listen-server-ports.sh ${STUDENT_USER}@$STUDENT_IP:/home/${STUDENT_USER}/listen-server-ports.sh || fail "Could not copy listen-server-ports.sh script to server"
13+
ssh -i id_rsa ${STUDENT_USER}@$STUDENT_IP chmod 755 /home/${STUDENT_USER}/listen-server-ports.sh || fail "Could not set permissions of listen-server-ports.sh script on server"
14+
ssh -i id_rsa ${STUDENT_USER}@$STUDENT_IP "sudo nohup /home/${STUDENT_USER}/listen-server-ports.sh &>/dev/null < /dev/null &" || fail "Could not execute listen-server-ports.sh script on server"
15+
16+
echo
17+
for port in 80 443 3000 3001; do
18+
echo $port; nc -w 1 $STUDENT_IP $port
19+
done
20+
21+
ssh -i id_rsa ${STUDENT_USER}@$STUDENT_IP sudo killall listen-server-ports.sh
22+
23+
echo
24+
for port in 80 443 3000 3001; do
25+
echo $port; nc -w 1 $STUDENT_IP $port && echo NOK || echo closed
26+
done
27+
28+
ssh -i id_rsa ${STUDENT_USER}@$STUDENT_IP rm -f /home/${STUDENT_USER}/listen-server-ports.sh
29+
ssh -i id_rsa ${STUDENT_USER}@$STUDENT_IP "sudo ls -laR /home/*/.ssh"
30+
31+
echo
32+
ssh -i id_rsa ${STUDENT_USER}@$STUDENT_IP hostname
33+
ssh -i id_rsa ${STUDENT_USER}@$STUDENT_IP cat /etc/hostname

0 commit comments

Comments
 (0)