I am working for the Catholic Education Office in Australia and have recently been having trouble with kids at different schools brining their personal laptops into the school, signing a contract saying they will not access the network (some schools just do not have the capacity to take on any more devices) and doing it anyway.
Being students, the first thing they do is go to youtube and stream video all day, and the second is start all their torrents they have downloaded from home. Don't ask me why, but we are not allowed to block torrenting.
To combat this, I have been writing a bash script for macs that will attempt to contact a host and, if succesfull, write a whole lot of data to a file and upload it to a local server via FTP.
I have finished the main functionality of the script but think I have been staring at it for too long and cannot figure out why I am getting
Code:
./MacPing.sh: line 45: syntax error: unexpected end of file
after executing. I have gone over all the code so many times, tried different tweaks and everything I can think of but cannot get it to work!
Pretty much, I am asking for help as I consider myself a rookie with bash scripting.
Code:
#!/bin/bash
# Script Name: MacPing.sh
# Author: Cameron Exley
# Date: 13.11.2011
# Details: Script will try to ping the (6776) FNP. If it can, it will upload a file to specified server.
# The point of this script is to ensure students who have been allowed to bring laptops on site do not access
# the network.
# Set the Varialbles
HOST="6776fnp01.ceoparr.local" # Host you wish to contact
OWNER="Cameron Exley" # The name of the student - for identification purposes
WriteFile="~/Sites/written.txt" # Text file you wish text to be written to
FTP="mac01-6776.ceoparr.local" # The FTP server you wish to upload the output file to
FTPUser="reports" # The username used to authenticate to the FTP server
FTPPass="not-secure" # The (insecure, clear text) password for the FTP username
USER=$(whoami) # Current User
if ping -c 1 $HOST # Attempt to make contact with specified host
then # If Successfull
MAC=$(ifconfig | grep ether | cut -c 7-23) # Dump all MAC addresses into variable "MAC"
TIME=$(date) # Dump the time & date into variable "TIME"
echo "The computer containing the following MAC addresses: # Write all collected information to specified text file
$MAC
accessed the network on this time:
$TIME
The owner of this device is: $OWNER
This script was run under the user: $USER" > "$WriteFile.txt"
ftp -n $hostname <<EOF # Create an FTP sesion with the specified host
quote user $FTPUser # Use the specified username
quote pass $FTPPass # Use the specified password
binary # Set binary mode
put $WriteFile "Reports/$OWNER - $TIME.txt" # Transfer the file
quit # Close the FTP shell, killing the session at the same time
EOF
else
echo "im not accessing the network"
fi
#There will be a repeat function in here for every 5 minutes - Unfinished