Friday, May 11, 2012

FreeBSD Crontabs location

This is a quick blog post, mainly for my notes.  In FreeBSD the users crontabs are stored in /var/cron/tabs by default. This is different than I'm used to coming from RHEL and CentOS world where crontabs where stored in /var/spool/cron/

FreeBSD Cron documentation: http://www.freebsd.org/doc/handbook/configtuning-cron.html

Thursday, May 10, 2012

How I learn a programming language

Today I'm going to talk about how I learn a new programming language.  Let me start by saying that I've never fully mastered a programming language, or even come close.  My roles are that of sysadmin and not of an actual programmer.  What generally happens is I'm given some task to accomplish, such as modify an already written report in our home brewed application.  I will dive into the report and figure out where I need to start modifying things. Or I need to come up with a new process, but since the rest of the home brewed application is written in PHP, I'll write the new process in PHP as well, just to keep everything consistent.

I learn programming  by looking at running code and modifying it to do something else or do the same thing but better or more accurately.  I have trouble reading through a book and doing the simple examples and building upon that knowledge.  It comes from already knowing a bit about programming and feeling dumb for re-reading what a variable is and how to assign it (pretty much the same in all programming languages).

At my last position I was able to learn a lot of PHP and I became very comfortable with it. I had worked with PHP a bit prior to this, but honestly, I had forgotten most of what I had learned.  In this case, that is probably for the best, it was all spaghetti code and crap for the most part.  The one thing that helped me the most was a good editor (Netbeans for PHP) and of course documentation.

My new position is with a firm that runs perl for nearly 100% of their code base.  I've always had a hard time reading perl code in the past (Mostly nagios plugins). Perl uses a lot of syntax that doesn't explain what its doing just by reading it in english.  So my typical take something that works and modify it has been a slower process.  I'm able to get the end result that I'm looking for, but I wouldn't say "I UNDERSTAND HOW" this code works or what it honestly does.

This had led me to reading the first few chapters of a book (http://www.perl.org/books/beginning-perl/) so that I may understand the HOW something works and WHY it works, not just that it does. This might be the first programming book I actually read all the way through! So far some of the wizardry of perl is going away because I know or at least know where to look up what "=~" does and not have to guess.  Some other resources I've used is of course Stackoverflow.com.  Some of the users there leave answers that don't just give an answer, but explain how and why it works and examples of other ways to do the same thing.

How do you guys learn a programming language?  What tools do you find are the best for learning a new programming language?


Monday, April 23, 2012

FreeBSD sed -i Error "sed: 1: "FILE": bad flag in substitute command: '.' "

On FreeBSD if you use the "-i" flag with sed you must specify a backup file.  The simple fix, if you don't want a backup file is to use "" (two quotes, no space between them).  You could also use any other filename you wished.

Examples:
BAD: sed -i s/192.168.1.1/192.168.1.44/g file.txt
GOOD: sed -i "" s/192.168.1.1/192.168.1.44/g file.txt

Wednesday, April 18, 2012

Updating the Locate database in FreeBSD (updatedb)

When I was running CentOS boxes if I needed to find a recently installed program or new file I would just run updatedb.  That however doesn't work as expected on FreeBSD (9.0 in my case).


When I first installed the machine I tried to run locate SOMETHING and got the error message locate: "database too small: /var/db/locate.database"


My first instinct was to run updatedb, which of course returns "updatedb: Command not found.".  It turns out there is a weekly cron job that will update the locate database, but if your server isn't on then (as is the case for me, since its a virtual machine on my local PC to toy around with) then you need to run the command manually. 


Just run the following script: "/etc/periodic/weekly/310.locate".  It may take a few minutes to run so just let it do its thing, or run it in a screen session.


By the way, I will most likely be posting a lot of FreeBSD tips and tricks in the coming months, as my new company runs mostly FreeBSD and Perl.