Thursday, April 01, 2010

bash oneliner to clear out apache httpd semaphores

If your seeing the following error message in your apache error logs

[emerg] (28)No space left on device: Couldn't create accept lock

You probably need to clear out some stale httpd semaphores. The following oneliner will do that for you.

ipcs -s | grep apache | perl -e 'while () { @a=split(/\s+/); print `ipcrm sem $a[1]`}'

Friday, March 26, 2010

log log log

Log stand and error outs to syslog and prefix it

#!/bin/bash
/usr/local/bin/something 2>&1 | logger -p daemon.notice -t ${0##*/}[$$]

Saturday, February 13, 2010

Reload nginx config

First make your changes to nginx.conf.

Then run the following command to test the new configuration:

# nginx -t -c /etc/nginx/nginx.conf
2007/10/18 20:55:07 [info] 3125#0: the configuration file /etc/nginx/nginx.conf syntax is ok
2007/10/18 20:55:07 [info] 3125#0: the configuration file /etc/nginx/nginx.conf was tested successfully
Next, look for the process id of the master nginx process:

# ps -ef|grep nginx
root 1911 1 0 18:00 ? 00:00:00 nginx: master process /usr/sbin/nginx
www-data 1912 1911 0 18:00 ? 00:00:00 nginx: worker process
Lastly, tell nginx to reload the configuration and restart the worker processes:

# kill -HUP 1911

taken from:
http://snippets.aktagon.com/snippets/93-Change-nginx-configuration-on-the-fly

Monday, February 01, 2010

bash one liner (essentially) to loop through list of files and upload using rsync

for f in `cat file-includes.txt`; do rsync -avz $f user@server.ip:/base-path/$f; done

you could also do the -e 'ssh -i /path/to/preshared/key' to avoid the rsync password prompt on each connect

for f in `cat file-includes.txt`; do rsync -avz -e 'ssh -i /path/to/preshared/key' $f user@server.ip:/base-path/$f; done

I find that this works better for only syncing a short list of files than trying to use the rsync switch --include-from=/path/to/file-includes.txt along with the --exclude-from=/path/to/file-excludes.txt or the --exclude=*

for some reason i couldnt get it to exclude everything BUT what was in my includes-from txt file.


Here is an even more expanded version that creates the white list of files for you containing all visible files in the current directory. You will probably want to modify it so that it only includes a subset of that. Otherwise it is pretty pointless (because it just does what rsync normally does uploads all changed files). You can hand create your white list of files to upload or use svn commit messages even.

ls -1 ./ > ./file-includes.txt; for file in `cat ./file-includes.txt`; do rsync -avz -e 'ssh -i /path/to/preshared/key' $( readlink -f "$( dirname "$file" )" )/$( basename "$file" ) user@server.ip:/base-path/$( readlink -f "$( dirname "$file" )" )/$( basename "$file" ); done; rm ./file-includes.txt

Tuesday, January 19, 2010

mysqldump to comma delimited file

mysqldump -u username --password=pass -h hostip -t -T./ dbname tablename --fields-enclosed-by=\" --fields-terminated-by=,

Sunday, January 17, 2010

syntax reminder on how to send mail from the command line

I always forget the params for this stuff

mail -s "subject" -c "person.to.cc.to@blah.com another.person.to.cc.to@blah.com" person.for.to.address@blah.com < /path/to/message/contents/text/file.txt

Sunday, January 03, 2010

page up down in vi in mac os terminal

Move up or down in “vi” from Mac OS X terminal:

Then CTRL-B and CTRL-F should do the trick.

.vimrc settings

These are my current vim settings

let mysyntaxfile = "/Users/jessesanford/.vim/go.vim"
syntax on
set nu
set ai
set tabstop=4
set ruler
set laststatus=2
set showmode
set expandtab
let loaded_matchparen=1