Add PATH= to beginning of a users crontab

Puts the correct PATH into a users crontab, so you no longer have to use absolute paths inside cron.
We executed it on all servers via puppet / console.

sudo su root
echo 'PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin' > /tmp/cron
crontab -l -u deploy  | grep -v PATH= >> /tmp/cron
cat /tmp/cron | crontab - -u deploy

Advanced sed regex

Some sed regex stuff I finally understood:

  • always use single quotes or you will go insane with escaping or strange errors
  • there is no \d and no +(at least on mac, on gnu its \+ (thx tobi!)), but you can use \{1,\} or repeat the pattern
    echo a1235b | sed 's/[0-9]\{1,\}//' --> ab
    echo a1235b | sed 's/[0-9][0-9]*//' --> ab
  • () and {} are escaped by default
    echo a{()}b | sed 's/{()}//' --> ab
  • escape ( and { to use them normal
    echo acccb | sed 's/\(c\{3\}\)/\1-\1/' --> accc-cccb
  • the matched string is &, matches from braces are \x
    echo acccb | sed 's/c\(c\)\(c\)/-&-\1-\2/' --> a-ccc-c-cb
  • To only print matched lines, use -n and /p
    echo 123 | sed -n 's/5/x/p' --> nothing
    echo 123 | sed -n 's/1/x/p' --> 1x3