Blind Not Dumb (Posts about UNIX)https://www.feoh.org/categories/unix.atom2024-01-21T01:02:41ZChris PattiNikolaMove over TextMate. MacVim is the new kid in town!https://www.feoh.org/posts/move-over-textmate-macvim-is-the-new-kid-in-town.html2011-09-09T17:41:00-04:002011-09-09T17:41:00-04:00cpatti<div class="line-block">
<div class="line">For years I've been rather proud of the fact that I'm a total polyglot when it</div>
<div class="line">comes to editors. I'm comfortable on both sides of the fence, using Emacs, Vi,</div>
<div class="line">TextMate, EditPlus, or even the venerable /bin/ed whenever that makes sense.</div>
<div class="line"><br></div>
<div class="line">But for the first time in a long time, my current (awesome! :)) job at <a class="reference external" href="https://www.bluestatedigital.com">Blue
State Digital</a> has given me the opportunity to</div>
<div class="line">branch out and do quite a bit of real software development.</div>
</div>
<div class="line-block">
<div class="line">I first encountered TextMate shortly after I came to OSX. It's a great editor,</div>
<div class="line">and I have a tremendous amount of respect for Alan Odegard of <a class="reference external" href="https://www.macromates.com">Macromates</a></div>
<div class="line">software. He has just about single handedly created not only an amazing</div>
<div class="line">editor, but a vibrant and loyal community around his program, and he's to be</div>
<div class="line">commended for that.</div>
</div>
<div class="line-block">
<div class="line">I would have remained happy in TextMate land, but for the fact that my most</div>
<div class="line">recent job has me going back to where it all started for me - server side UNIX,</div>
<div class="line">Linux to be exact.</div>
</div>
<div class="line-block">
<div class="line">So, I editing files on my Mac using Expandrive to remotely mount them, but</div>
<div class="line">quite frankly that's a pain in the neck I just don't need to deal with.</div>
</div>
<div class="line-block">
<div class="line">With Vim, I can memorize one set of keystrokes for everywhere I might need to</div>
<div class="line">be.</div>
</div>
<div class="line-block">
<div class="line">And with MacVim, I get a nicely streamlined, beautifully Aqua-fied interface,</div>
<div class="line">with all the creature comforts TextMate provides and more.</div>
</div>
<div class="line-block">
<div class="line">What's more, there are a number of folks making the same transition, so there</div>
<div class="line">are some excellent articles and websites out there to ease the transition like</div>
<div class="line"><a class="reference external" href="https://www.jackkinsella.ie/2011/09/05/textmate-to-vim.html#masthead">this guide on making the
switch</a> or</div>
<div class="line">the excellent <a class="reference external" href="https://vimcasts.org">VimCasts</a> series of Vim tutorial screen</div>
<div class="line">casts. They cover everything from the basics to some fairly advanced tips and</div>
<div class="line">tricks on more complex Vim modes and integrations, and is written by a TextMate</div>
<div class="line">to Vim switcher.</div>
</div>
<div class="line-block">
<div class="line">Right now I'm writing this post on the excellent</div>
<div class="line"><a class="reference external" href="https://www.vim.org/scripts/script.php?script_id=3510">VimRePress</a> plugin for</div>
<div class="line">Vim that allows you to author and manage your Wordpress blog right from within</div>
<div class="line">the editor! Very sweet :)</div>
</div>
<div class="line-block">
<div class="line">So, it's a brave new world, and I'm excited by the opportunity to get</div>
<div class="line"><strong>really</strong> good at Vim so I can push my editing productivity through the roof</div>
<div class="line">:)</div>
</div>Managing crontabs with Githttps://www.feoh.org/posts/managing-crontabs-with-git.html2010-10-20T15:24:00-04:002010-10-20T15:24:00-04:00cpatti<p>April 2012 Update: Nowadays we use<a class="reference external" href="https://www.opscode.com/chef/">Chef</a>from Opscode solutions to manage our crontabs, and just about everything else in our enterprise infrastructure. It rocks :)</p>
<p>Time and time again over the years I've dealt with the same problem - who took a random pot shot at some critical user's crontab file and deleted things without asking?</p>
<div class="line-block">
<div class="line"><br></div>
<div class="line">All of a sudden, someone realizes that some function that's supposed to run every so often has stopped, and in fact hasn't run in weeks. You sniff around - nope, no errors in the logs, in fact no logs at all!</div>
</div>
<p>Then you look at the crontab for the user in question and realize that the lines invoking the script that used to be there have either been deleted or commented out. What the? Who did this, and why?</p>
<p>Git to the rescue! With the help of a simple Bourne Shell script, you can keep your crontab managed so you'll not just be able to see who changed what and when, but if you have the Git hook installed to send mail on commits, you can be notified of those changes in real time. Pretty cool eh? :)</p>
<p>Since crontab has no built in security precautions other than requiring you to BE the user whose crontab you're submitting, we can't lock people not using this script out, but if you tell everyone that changes they make outside of the script may be summarily ignored and overwritten (and put something to that effect in the comment block at the top of your crontab) you should be in good shape. The script will compare what's in Git with what's currently installed in cron, and if there are discrepancies it will give you a chance to cleanly exit and resolve them, or allow you to ignore them and roll forward with editing and submitting what's in Git.</p>
<p>Here's the script. It assumes you're running as your regular user and have sudo privs to the user whose crontab you wish to edit. It also assumes you've created a Git repository called system_cron.git</p>
<p>To set it up, just edit reponame and gitrepo to appropriate values for your site and copy the script to somewhere folks can access it in their PATH.</p>
<p>To use it, just invoke it with the user whose crontab you want to edit - for example:<code class="docutils literal">edit_crontab.sh build</code></p>
<pre class="literal-block">#!/bin/sh
export tmpdir="/tmp/crontab_$$"
if [ $# -lt 1 ]; then
echo "Usage: $0 "
exit 1;
fi
if [ -z "$EDITOR" ]; then
echo "No editor found. Using vim."
export EDITOR="/usr/bin/vim"
fi
crontab_user=$1
crontab_file="`uname -n`-$crontab_user.crontab"
echo "crontab_file=$crontab_file"
git clone /home/git/system_cron.git $tmpdir
cd $tmpdir
sudo -u $crontab_user crontab -l > currcrontab_$$
if [ $? -ne 0 ]; then
echo "sudo to user $crontab_user failed! Do you have sudo privs?"
exit 1;
fi
diff=`diff currcrontab_$$ $crontab_file`
if [ $? -ne 0 ]; then
echo "Currently running crontab for $crontab_user differs from Git!"
echo "Here are the differences:"
echo $diff
echo
echo -n "Continue editing / submitting what's in Git? (Y/n): "
read yesorno
if [ "$yesorno" != "Y" ]; then
echo "Very good. Exiting."
exit 1;
fi
fi
$EDITOR $crontab_file
echo "Here are your changes:"
git diff --exit-code $crontab_file
if [ $? -eq 0 ]; then
echo "No changes made. Not submitting anything."
exit 1;
fi
echo -n "Submit these changes to Git and crontab? (Y/n): "
read yesorno
if [ "$yesorno" != "Y" ]; then
echo "Your changes are in $tmpdir/system_cron/$crontab_file."
echo "Please clean up this directory when you're done with it."
exit 1;
else
git commit $crontab_file
if [ $? -ne 0 ]; then
echo "There was a problem committing your crontab to git!"
exit 1;
fi
git push origin master
if [ $? -ne 0 ]; then
echo "There was a problem pushing your crontab to git!"
exit 1;
fi
# if we made it this far. We're all good. Install that puppy!
echo "Installing your crontab."
sudo -u $crontab_user crontab $crontab_file
if [ $? -ne 0 ]; then
echo "ERROR! Your changes were NOT installed! Something went wrong."
exit 1;
fi
fi
echo "Cleaning up tmp directory..."
#rm -rf $tmpdir</pre>