The idea behind this script is simple. There is a file stored on your web server. Every 5 or so minutes this script will check this file. If you have found that you laptop has been stolen you change this file. Your computer will then take pictures of your thief, along with your computer IP address and other information. It will then email this back to you so you can contact the authorities and get your Mac back. This script is by no means perfect. But it is the method I have developed. It works which is the most important thing.
The Code
In this section I will move down the script line by line (bypassing comments). I will tell you what they mean and why they are there. As well as if you have to change anything. You do have to do a couple of extra steps to make it work. It doesn’t work right out of the box.
#!/bin/sh
This first line tells Terminal that we are running an shell script. This makes sure we are running the right interpreter.
robber=`wget http://www.example.com/file.html -O - -o /dev/null`
This is file you will change if you have found that your Mac has been stolen. The file should be stored on your server. It should contain anything but the number one (1). Type in anything you want so it isn’t a blank file. This is a variable that will be used to determine a function within the if statement.
thedate=`date`
A lot of the file names will include dates within them so you know what time the image was taken. This variable sets the date. This is so the same date number is present over all of the functions within the script. The script takes a while to execute, we don’t want it changing.
path="/A/Path/To/Hidden/Location/"
This is the file path to where you want to store your files. Make it well hidden. Make sure to include a backslash at the end and the beginning.
if [ "$robber" != "1" ]; then
echo Test Done At $thedate, Pass >> $path”Checks”.txt
echo Test Done At $thedate, Pass >> $path”Checks”.txt
This is the main if statement. The first line basically means if you find anything but the number one then do the second line. The second line writes to a log file that the check has been completed. This includes the data and the word “Pass”. It will then write it to the end of the file stored in your secret location. If you have read the previous post, I developed a method in which it would right to a different file and then combine them. I did this because I couldn’t work out how to write to the ends of files. The double arrows (>>) do this for you.
exit 1
else
else
This exits with a 1. I don’t know why I did this, all the examples of if statements scripts I looked at included it. The else section sends us onto the bulk of our code.

Tidak ada komentar:
Posting Komentar