Category: Linux
Useful Bash Tricks and Commands
I spend a lot of time using the command line, and I find these features particularly useful. This might be old news to some, but they are still immensely helpful. (Also, these are extremely hard to google for, so hopefully this will save you time in more ways than one!) I tried to include as many examples as I could to make these easy to understand.
Easy way to add paths to $PATH in bash
This little script is a convenient way to add paths to your
$PATH variable without worrying about duplication. I generally break out my .bash files to be organized across multiple servers/computers and each one seems to need different paths appended -- so thats where this little guy comes in handy. Just a simple push_path and no worries.
Send Entourage mails from the command line with Ruby
I've been spending a lot of time creating reports lately, and I generally live in a terminal, so naturally I started to think of ways to easily send emails with these reports attached. I'm stuck using Microsoft Entourage here at work, but thankfully they have a pretty robust AppleScript library. Mixing some stuff together I pulled together this Ruby script which will allow me to do some neat stuff:
- pipe data into the
emailcommand to create a body - use aliases as groups to send emails to common groups of people, etc
- add multiple attachments to emails straight from the command line!
- not have to move my hands from the keyboard when sending emails!
osascript to execute the AppleScript. When run it will pop open a new Entourage mail window with the To/CC/Subject filled out, as well as any attachments and moves focus to the window. If I had piped anything to STDIN that would be the body, otherwise it would blank and ready for a quick message. Then a quick CMD-ENTER and off the mail goes. Simple and elegant, yet kind of powerful :)
Check piped STDIN in Ruby Shell Scripts without Prompting
I was writing a small shell script in Ruby today that needed to check STDIN for data, but I didn't want to prompt the user to enter data when nothing was found (I only wanted piped in data). This turned out to involve a little more effort than just checking
STDIN.read.
Luckily, I found a solution at Footle that worked out great. Heres to anyone who needs _only_ piped in data from STDIN without prompting the user.
OpenSSL Encryption Fun
I re-discovered the fun that is OpenSSL's encryption today when I was cleaning up some bash aliases and though I'd share them.
This allows you to do some really stupid but fun things like encrypt backups, or messages to pass to a buddy. The uses are endless!
PHP 5.3.3 MySQLi compile woes: my_global.h and error: duplicate ‘unsigned’
It seems like every time I re-compile PHP I get some whacky error. Anyway, I was fortunate enough that a quick Googling found a solution from katmai for compile error.
I'm popping this up here as a reminder to my future self, as well as anyone else who stumbles into this.
If you get this error when attempting to compile PHP 5.3.3 with MySQLi on, in my case, Snow Leopard
/usr/local/include/mysql/my_global.h:1008: error: duplicate ‘unsigned’ /usr/local/include/mysql/my_global.h:1008: warning: useless type name in empty declarationWas solved with a simple patch to ext/mysqli/php_mysqli_structs.h
Sending mail with Ruby and ActionMailer
This is a simple, but useful little script I ended up writing to test some things. I found it easier to use this than to constantly use the
mail command. It basically wraps action mailer in a small ruby script so you can call it from the command line.
./spoofmail.rb --to=who@where.com --from=sjobs@apple.com --subject='Hey You!' --body='whatsup guy?'
or using STDIN
./spoofmail.rb --to=who@where.com --from=sjobs@apple.com --subject='Hey You!' < body_of_message
cat|./spoofmail.rb --to=who@where.com --from=sjobs@apple.com --subject='Hey You!' whatsup guy? ^dIt might come in handy one day when you need to mess with a co-worker or test a mail receiver... or something else?
Ruby unified diff using tmp files
This is admittedly ghetto, but I needed a super simple small-scale solution to creating unified diffs based off large blocks of text. The easiest way to do this was by creating temp file and using the native
diff command to do the comparison.
I've used this method for a really small snippets app for our intranet, which can be found on GitHub.
