Tuesday, August 12, 2014

Very useful bash $PS1 setting

My ~/.bashrc settings have a killer setting for how my shell prompt looks:

case $- in
   *i*)
export PS1="\[$(tput bold)\]\[$(tput setaf 6)\]\t \[$(tput setaf 2)\][\[$(tput setaf 4)\]\u\[$(tput setaf 1)\]@\[$(tput setaf 4)\]\H \w \[$(tput setaf 6)\]\[$(tput setaf 2)\]]\[$(tput setaf 4)\] \$? \\$ \[$(tput sgr0)\]" ;;

     *)  return ;;
esac


The result:

22:19:43 [myuser@myserver.example.com ~ ] 0 $

This shows the current system time, username@server FQDN, pwd, exit code of last command, and regular user or root prompt.

This works in both interactive and non-interactive shells (hence the case statement).  Enjoy.  Additional info can be found here:

Bash $PS1 generator
10 Bash $PS1 examples
Bashrc generator

Wednesday, July 9, 2014

Ruby Regex

Just wanted to pass along two very useful sites for regular expressions with Ruby

Ruby regex calculator:

http://rubular.com/

Ruby regex documentation:

http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm

Wednesday, May 22, 2013

Google search plugin for terminator

This is going to save me 10 minutes a day.  Props to the developer.

https://github.com/choffee/terminator-plugins

This is a plugin which adds a function to the context menu of terminator (my favorite Linux-based terminal emulator) which will search Google for the selected text.  Before I discovered this, I would select the text, copy it to a browser like Chrome or Firefox, then searched Google.  This is going to make me much more efficient.

Wednesday, January 16, 2013

Capistrano with sudo

Capistrano with sudo

An easy way to execute commands with sudo from within a capistrano job is to add the prefix  #{sudo} to a command within your capistrano task.  For example:

task :make_protected_dir, :roles =>db do
  run "#{sudo} mkdir /root/mydir"
end

Another example:
task :restart_httpd, :roles =>app do
  run "#{sudo} /etc/init.d/httpd restart"
end

Then from the command line, load your file with these entries:

cap -f capfile

Then, execute the commands:

cap make_protected_dir

cap restart_httpd

More info:

https://github.com/capistrano/capistrano/wiki/2.x-DSL-Configuration-Tasks-Task

Tuesday, January 1, 2013

S3 Utility

Here is a great tool for working with Amazon S3.  It even has a wide variety of repos available (easier than compiling from source).  s3cmd is very easy to setup.  It is the easiest to work with of all the S3 tools I have used.

Thursday, August 23, 2012

Trace your python programs

Bash programming has a very helpful command of:

bash -x myscript.sh

This will show you what bash is doing while running through myscript.sh. Python has the same functionality, through this command:

python -m trace --trace myscript.py 

Very useful in debugging python programs.  Additional info:

http://docs.python.org/library/trace.html


Friday, August 3, 2012

Create ssh public key from private key

If you have a private key and want to create the public key from that (to put in ~/.ssh/authorized_keys, for example), do the following:

ssh-keygen -f <my_private_key> -y > <my_public_key>

For example:

ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub


If you are using this to ssh with keys, add my_public_key (eg. ~/.ssh/id_rsa.pub) to ~/.ssh/authorized_keys on the remote server.

Then ssh with the private key to the remote server to test.


Monday, May 14, 2012

EC2 Bundling an AMI -- Server.InternalError: An internal error has occurred


Once you try to re-bundle an OS image that has been previously bundled, it will complain about /etc/ec2/amitools/cert-ec2.pem not being present.  I figured that was my certificate, but it is  EC2's X.509 public key certificate, not mine (docs are somewhat confusing about that).  Since they were stripped out of the AMI last time it was bundled, I reinstalled the tools to restore these certs and no errors any more.

AWS API tools:

http://aws.amazon.com/developertools/368

Hope this helps.

Original EC2 forum posts:

https://forums.aws.amazon.com/thread.jspa?messageID=345021

https://forums.aws.amazon.com/message.jspa?messageID=344101


Wednesday, April 25, 2012

Tuesday, March 27, 2012

Install Cisco AnyConnect on Ubuntu/Debian/Mint 64 bit

Looks like there are no 64 bit Cisco AnyConect VPN Clients.  Here is a workaround to get them working on a Debian-based 64 bit OS:

http://www.virtualcorner.nl/?page_id=220

Monday, March 26, 2012

Linux Mint on Gigabyte GA-Z68X-UD3H-B3

I tried to install Linux Mint on a desktop with Gigabyte GA-Z68X-UD3H-B3 motherboard with its Intel raid array configured with two of three hard drives.  I wanted to install Linux Mint 12 x64 on the third drive.  When trying to boot, I got the error message:

udev timeout killing /sbin/modprobe -bv pci:

I had to add the grub option of nomodeset as a kernel paramater.  It then was able to install from there.  Here are more details:

http://forums.linuxmint.com/viewtopic.php?f=46&t=95351&p=547012#p545731

Thursday, February 23, 2012

pv

This was so good I had to repost it here.  It is about a useful utility called pv which shows a progress report of running processes:

http://www.dp.cx/blog/pv--one-of-the-most-useful-applications-around.html

Wednesday, December 14, 2011

Make script compatible with chkconfig

To make an init script compatible with chkconfig (to autostart on next runlevel change), add the following header to your script within it's /etc/init.d/ file, for example, /etc/init.d/myscript

#!/bin/bash

#
# myscript     init script to manage myserver
#
# chkconfig: 2345 90 35
# description: A server which does amazing things.
#


Now, add it with these commands:

/bin/chmod +x  /etc/init.d/myscript
/sbin/chkconfig myscript --add
/sbin/chkconfig myscript on
/sbin/chkconfig myscript --list
myserver       0:off    1:off    2:on    3:on    4:on    5:on    6:off


Within the chkconfig definition line, 2345 means the runlevels it will be started under, and 90 35 are the start and kill priorities, an integer between 0 and 99.  In this example, it would be started as one of the last services, and killed (stopped) as one of the earlier processes.

Tuesday, November 29, 2011

Just kill the process

/bin/kill -9 `/bin/cat /var/run/snmpd.pid`

To kill just the PID reported by the process as the active PID (with a shotgun, -9) and nothing else, use this shortcut.

Thursday, November 3, 2011

sed add line at end of file

If you want to add a a line of text to the end of a file, and want to do the edit in place, use this syntax:

sed -i '$ a\This is some sample text.'  /foo/bar

Monday, October 31, 2011

Visual explanation of SQL joins

I wish I had these pictures in my head when I started learning about joins in SQL.  Might have been a DBA instead of a systems engineer.


http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

Sunday, October 9, 2011

Charge iPad or iPad2 over usb in Linux

First, follow these instructions:

http://korenkov.info/ipad-ipad2-charge-ubuntu

For later versions of udev (I tested this on Ubuntu 11.04), make sure that /etc/udev/rules.d/95-ipad_charge.rules looks like the following examples.

For iPad:

ENV{DEVTYPE}=="usb_device", ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="129a", RUN+="/usr/bin/ipad_charge"

For iPad2:

ENV{DEVTYPE}=="usb_device", ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="129f", RUN+="/usr/bin/ipad_charge"

Then restart udev or reboot.

Wednesday, October 5, 2011