Special cron entires

There are some special entries that can be used when creating a crontab entry (crontab -e), most of which are just shortcuts for the standard crontab entries that we all know and love.

You can use them in your crontab just like you would a normal entry:

# m h dom mon dow  command

# Say hello each time the machine boots up
@reboot echo 'Hello world. I just booted up'

# Say Happy new year, using both forms of entry
@yearly echo 'Happy new year'
0 0 1 1 * echo 'Happy new year from me too'

The @reboot entry could be useful for keeping track of when a machine is rebooted. Just add the crontab and each time the machine restarts you'll get an email with any output from the crontab (in this case, "Hello world. I just booted up")

Possible entries

There are nine possible aliases, some of which are just aliases for each other (such as @yearly and @annually)

Entry Description Equivalent entry
@reboot Run once, at startup None
@yearly Run once a year 0 0 1 1 *
@annually Same as @yearly 0 0 1 1 *
@monthly Run once a month 0 0 1 * *
@weekly Run once a week 0 0 * * 0
@daily Run once a day 0 0 * * *
@midnight Same as @daily 0 0 * * *
@hourly Run once an hour 0 * * * *

I'm not sure I'd recommend using any of these (except maybe @reboot) as the standard syntax is well known by anyone that should be editing a crontab, but it's interesting to know that there are aliases in there for common time periods.jJ;w

(via mkaz (now offline))

[ Read More ]

git and diff-highlight

diff-highlight is a contrib script that ships with git. It's a better way to visualise a diff when the changes are small words, not entire lines/paragraphs. It's hard to explain, so here's an example (diff-highlight is the script):

[ Read More ]

git push

A nice quick tip to get the ball rolling again.

If you've ever deleted a branch on a remote system only to have it recreated when you git push, this one's for you. It will make git only push the current branch by default; other branches are not pushed to the server. This helps to ensure for example that deleted branches do not get re-pushed accidentally.

git config --global push.default current`

If you do want to push all branches you've got locally, you can use the --all flag like so:

git push --all
[ Read More ]

The Unix Toolbox

This article originally appeared in the December 2013 issue of PHP Architect

The beauty of a Unix-based operating system is that it has a multitude of useful tools that most people don't know about. You can use them on their own, chain them together, you can do almost anything you can think of.

We'll take a look at some popular tools and some lesser known gems. As well as tools, we'll cover tips and tweaks for making your command line do all the work so that you don't have to. From search and replace to installing software without having to find it first, the command line can do it all!

[ Read More ]

A better git diff

Whitespace is like git diff's krypton, it makes changes that are actually tiny look much more complicated than they actually are. Thankfully, git comes with a few flags that you can use in conjunction with git diff to make life a bit easier.

The first option is --ignore-space-at-eol. This flag makes git diff ignore any changes to whitespace at the end of a line. Most developers have options to automatically trim trailing whitespace, but if you're working in a team that doesn't have it enabled you might find this option useful.

[ Read More ]