“Lock your computer”: What really happened

As a result of a “fun” prank, I learned a bit about cron scheduling!

Screen shot of a terminal window that says "lock your computer"

Yesterday – April Fools’ day – I published a post about an apparently traumatic incident with my personal laptop. That post was somewhat of an April Fools’ joke, although it was mostly true up until the point where I “just went out to buy a new laptop”.

What really happened: my friend and co-worker, the clever and benevolent Aaron Jorbin, added a say command to the cron scheduler on my computer, presumably when I was visiting the NYC office and foolishly left my laptop unattended for a few moments. What a clever prank!

If you happen to make a similar mistake – or you Google “computer is saying lock your computer” and find no results, like me – then here’s what you can do.

Cron and Crontab

Heavily paraphrasing the Wikipedia article: the term cron refers to a software utility that schedules “jobs”, or commands, to run at time-based intervals on Unix-based operating systems like Mac OSX or a Linux. I first became familiar with the notion of cron jobs via WordPress, though it is generally associated with operating system level software.

On Mac, you can schedule these jobs using crontab, which is a program – or file? – that would contain a list of jobs with a specific format that specifies the command and how often it should run.

To view the crontab, open a command line, i.e. Terminal, and enter the command: crontab -e.

Hopefully there is nothing in there, but if you left your computer unattended (and “unlocked”) in a room Aaron, you might see something like this:

The command itself is:

* * * * 4 say "lock your computer"

According to this article, the structure above equates to:

Argument 1: Minute (0 – 59)
Argument 2: Hour (0 – 23)
Argument 3: Day of Month (1 – 31)
Argument 4: Month (1-12)
Argument 5: Day of Week (0 – 6) Sunday = 0
Argument 6: Command

And we can break it down like this (credit to robg in this Macworld post):

#min    hour    mday    month   wday    command
* * * * 4 say "lock your computer"

Where mday is day of the month and wday is day of the week. The * means “every”. So, the command in my crontab will run every minute of every hour of every day of the month of every month on Wednesdays.

What? Meh, something like that. I’m done spending time on this part of the post.

The next step, after running crontab -e is to learn enough Vim commands to delete it. :wq has served me well until now.

A few Vim commands

  • x – Delete.
  • : – means you are about to enter a Vim command.
  • esc – command mode. If you every get stuck, you can press esc and enter command mode.
  • :w – Write, or save, the file.
  • :q – Quit.
  • :wq – The trusty “write and quit” command.

So, all together, you would:

  1. crontab -e – Open the crontab-file-thing in Vim.
  2. x – press it until the evil command is gone.
  3. :wq – Save and quit.

Amazing!

In Conclusion

The story in my April Fools’ post is true up until my giving up and buying a new computer. I did have Apple Care though, and was on the phone with them for about an hour. They were baffled. I figured it out when screen-sharing with another co-worker who said, “that sounds like a say command” and I was like, “I KNOW WHAT THIS IS”.

Anyway, in the spirit of writing the blog post I wish I’d found, if you come across this post and are also one of Aaron’s victims, you are welcome.