dinsdag 14 april 2009

rsync over another ssh port

if you want to rsync over port 7777 instead of 22 use

rsync -vnze 'ssh -p 7777' user@myserver.fake:/src/dir/* /dest/dir

-n is a dry run!

zondag 5 april 2009

bulk rename bash

ls *old|sed 's/\(.*\)\.old/mv \1.old \1.new/'|sh

from: http://www.moxleystratton.com/articles/rename-files-bash

vrijdag 13 maart 2009

one line loop bash

check php files for errors

bash$ for f in $( ls *.php ); do php -l $f; done

vrijdag 6 maart 2009

woensdag 4 maart 2009

RSSH scp sftp rsync restrictive shell

rssh is a restricted shell, used as a login shell, that allows users to
perform only scp, sftp, cvs, rdist, and/or rsync operations. It can
also optionally chroot user logins into a restricted jail.

dinsdag 17 februari 2009

ssh port forwarding

ssh port forwarding example (port 8000)

ssh -C -N -L 8000:local_ip:8000 remote_ip


with compression.

woensdag 4 februari 2009

javascript nice urls

javascript nice urls

replaces spaces punctuation and some other crap.

str.replace ( /(_|\t| )+/g, "-" ).replace(/[^a-z0-9\-]|(^-)|(-$)/gi,"").toLowerCase ().replace ( /-+/g,"-");

woensdag 28 januari 2009

php curl twitter api

If you receive a 417 http status code when you try to post something using php and curl. Try to send an empty "Expect:" header with your request.

example:

$curl_conn = curl_init ( "http://twitter.com/statuses/update.xml" );
curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt ($curl_conn, CURLOPT_HTTPHEADER, array ( "Expect:" ) );
curl_setopt($curl_conn, CURLOPT_USERPWD, $user . ":" . $password );
curl_setopt($curl_conn, CURLOPT_POST, true );
curl_setopt($curl_conn, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $curl_conn, CURLOPT_POSTFIELDS, array ( "status" => $msg ) );
$response = curl_exec ( $curl_conn );

donderdag 22 januari 2009

mysql dumps

from:
http://mrothouse.wordpress.com/2007/01/15/mysql-restore-from-compressed-backup/

Copied a compressed database backup from the Production server to the Development server. The database backup file was compressed using bzip2 while piping from mysqldump.

mysqldump -u root -p –databases perfparse | bzip2 -z1 > perfparse.bkp.bz2

bzip2 Options

z = compression
1 = fastest compression (compared to 9 = best compression)

Used bunzip2 to uncompress while piping to mysql due to limited disk space.

bunzip2 < perfparse.bkp.bz2 | mysql -uroot -p

Very basic information, but I do use this blog for referring myself and others back to my notes.

maandag 15 december 2008

bulk rename bash

for f in oldprefix*; do mv "$f" "${f/oldprefix/newprefix}"; done

dinsdag 2 december 2008

simple python mail script

got it from here: http://www.eskimo.com/~jet/python/examples/mail/smtp_email.html


import smtplib
import email.Message

def mail(serverURL=None, sender='', to='', subject='', text=''):
message = email.Message.Message()
message["To"] = to
message["From"] = sender
message["Subject"] = subject
message.set_payload(text)
mailServer = smtplib.SMTP(serverURL)
mailServer.sendmail(sender, to, message.as_string())
mailServer.quit()

woensdag 29 oktober 2008

Leopard samba client

Some Mac leopard clients ignore the force create mode settings from your smb.conf which work with most other clients.

If you want stuff to work with those clients try this (user+group can read, write all, others cannot do anything):


create mask = 0660
force create mode = 0660
security mask = 0000
force security mode = 0660

directory mask = 0770
force directory mode = 0770
directory security mask = 0000
force directory security mode = 0770


http://discussions.apple.com/message.jspa?messageID=5904901

maandag 20 oktober 2008

php4-cgi with php5 apache2 module

Ran in a situation where I had to run php4 and 5 on the same box (but different folders).

On debian you'll have to install php4-cgi and enable apache mods (suexec, ssl, actions, mime) following VritualHost config worked for me:



<VirtualHost *:80 >

ServerAdmin bart@dlma.nl
DocumentRoot /var/www/tutos/HTML/
ServerName tutos.dlma.nl


ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory /var/www/tutos/HTML>
AllowOverride All
Options -Indexes

AddHandler php-script .php
Action php-script /cgi-bin/php4


</Directory>

</VirtualHost>

maandag 6 oktober 2008

switch user svn+ssh

If you want to change the username of your svn+ssh working copy (and the username is in the url i.e. svn+ssh://username@host.nl/repos ) the '--username' will not work. Instead you'll have to change the URL with the 'switch --relocate' command as follows:

$svn switch --relocate svn+ssh://username@host.nl/repos svn+ssh://newusername@host.nl/repos

dinsdag 30 september 2008

list scsi devices linux

The 'lsscsi' command lists the scsi drives attached to your system.

ubuntu (aptitude install lsscsi)

Also checkout the file
/proc/scsi/scsi


and the command hwinfo --scsi

maandag 22 september 2008

trac Integrety Error

If your trac starts giving you Intgrety Errors try to do a:


trac-admin /your/trac/path resync

maandag 1 september 2008

loop throught files with bash

For-in loops don't work well when you have filenames with spaces in them


#!/bin/bash
ls *.pdf | while read i; do
j=`echo $i | sed s/\.pdf/\.swf/`
pdf2swf "$i" -o "$j"
done

donderdag 28 augustus 2008

ssh X forwarding on your server

If you have an ubuntu/debian server running and want to run X apps through ssh -X you should "apt-get install xauth" for this to work.

woensdag 27 augustus 2008

tortoise SVN

In some cases tortoise svn (windows svn client) can't do checkouts of your repository and the following message is displayed:

"Not authorized to open root of edit operation"

Adding the following line to your svnserve.conf solved the problem for me:

"anon-access=none"

woensdag 13 augustus 2008

Hollandse hitmachines

Voor al uw nederlandse artiesten en hollandse hitmachines

http://www.watzitjenoutekijken.nl

convert int to a separate bytes

def intToBytes(self,n, bytecount):
""" returns the binary of integer n, using count number of digits """
str = ""

i=bytecount-1
#8 bit mask
mask = ~(sys.maxint^(pow(2,8)-1))
while i >= 0:
str = str + chr((n>>(i*8))&mask)
i-=1

return str

dinsdag 12 augustus 2008

convert bytes to an integer in python

ran into a situation where i had to convert some bytes to an integer value in python. This func does the trick. The mask is only used to have a counter of the same length counting backwards (hence the negation).
def bytesToInt ( self, bytes ):
""" convert certain amount of bytes to an integer """
size=0
i=0

mask = sys.maxint&(len(bytes)-1)
while i < len(bytes):
size = size|ord(bytes[i])<<((~i)&mask)*8
i+=1

return size

woensdag 23 juli 2008

rolling back with svn

Say you want to rollback (parts of) your svn repository to a certain revision. This can be done with svn merge.

it works like this:

$ svn merge -r 1481:1373 svn+ssh://your.host.com/srv/repos/subdir

where the first number is the current revision and the second number is the revision you want to 'rollback' to.

A list with changes should appear (also use svn status for this). If you think you're done do a commit and the changes will be done on the repository.

vrijdag 11 juli 2008

tcpdump

for ftp traffic
tcpdump -A -i eth0 tcp port 21

comes in handy when you want to see what passwords are used.

WEP cracking with aircrack-ng

Open three terminals

terminal 1:
$airodump-ng -c 4 --bssid FA:KE:FA:KE:FA:KE -i -w jah eth1

This is an exmaple that dumps only weak iv's (channel 4) interface eth1 from the AP with this particular BSSID

You can also do a scan for WEP AP's first by running "airodump-ng eth1" without any further args.

If you're seeing some traffic between the AP and the client (use bssid for reference). use aireplay like this (in the second terminal):

$aireplay-ng -3 -b FA:KE:FA:KE:FA:KE -h FA:KE:FA:KE:FA:KE eth1

the three means you're doing ARP. The -b is the AP. The -h is the client.

If you leave this running for some time you can use the third terminal to run aircrack on the .ivs file airodump-ng created. It'll try to crack the key every now and then so you can leave it running.

maandag 30 juni 2008

filenames beginning with a - (dash)

If you want to (for example) cd to a file starting with a dash (some mac users tend to use weird filenames like "-folder" ). do

$cd ./-folder

removing files matching a certain pattern

from the xargs man:

delete all .svn folder

$find /somedir -name .svn -print0 | xargs -0 /bin/rm -rf

xargs comes in handy when handling great amounts of files.

donderdag 26 juni 2008

replacing text in a bunch of files matching a certain pattern

Replace comes with mysql. It's a handy tool for sed/awk n00bs. This one I used to change some static paths while excluding all .svn folders and logfiles.

~$ replace '/var/www/mydir' '/var/www/newdir/' -- `grep --exclude-dir=.svn --exclude=*.log -clr "/var/www/mydir" ./*`

Of course there are other/better ways to accomplish this, look at this
http://www.brunolinux.com/02-The_Terminal/Find_and%20Replace_with_Sed.html

dinsdag 24 juni 2008

ejecting a cd from a mac (running OS X)

Before rebooting try in terminal:

$drutil eject

donderdag 19 juni 2008

page up / page down bash

add these lines to your /etc/inputrc to search backwards through history. It searches on the string already typef


"\e[5~": history-search-backward
"\e[6~": history-search-forward

woensdag 18 juni 2008

example post commit hook

Sample script for a conditional post-commit hook in bash. This post-commit hook updates a local copy (www directory) to the latest revision when files are changed within a certain directory.

#!/bin/bash
umask 0002

REPOS=$1
REV=$2
MATCH=`/usr/bin/svnlook -r $REV dirs-changed $REPOS | /bin/grep -c "just a string"`

if [ $MATCH -gt 0 ];then
/usr/bin/svn update /var/www/projects/mysite
fi

maandag 16 juni 2008

Never create a PagesController in Cake

While fiddling with cake. I got some weird error in my PagesController:

You are seeing this error because the action display is not defined in controller PagesController"




Whatever I did, it kept asking for a default view. After some searching it seems the PagesController is reserved for cake itself.


Reference: http://logs.cakephp.nu/cakephp/chat.log.2007-06-26