Sign on/Sign off logging script

I'd like to make a script that I can execute every time I sign on to my linux box that keeps track of the time and allows to me to add a remark to a file. So basically once I log in, I run the script, and it outputs the date and time to a text file (log.txt). But that isn't my problem.

I need to know how to make it so once i've executed the script in a session, it won't allow me to execute it twice until i've run a sign out script. I'd like it to say something along the lines of "Sorry, you are already signed in!" if i've already run the sign in script.

Then, I need to know what to add to the sign OUT script in order to make it go back to normal the normal signed out state.

I don't know if this makes any sense, but any input would be appreciated! I'll be checking the thread to answer any questions as often as possible. Thanks.

I guess the easiset way is to create a "lock file"

ie
The first thing you do is check to see if a "lockfile" exist, if not, then it must be the first time and you touch a filesomewhere.....ie create the lockfile

continue process the rest of the script

The last thing the script does before it ends is remove the lock file.

That way if it starts up again....it won't do any thing...because the previous execution created a lock file and is still open at that time....

does that make sense?