code at random

Wednesday, July 11, 2012

To use ssh in scripts, its sure the most secure way to use ssh-keys. But some times that isn't possible. In that case the security focuset aprocach in ssh to not accept plain passwords in a other way than direkt keyboard imput is a pain in the ass. I tryed different aprochs to go around this like using sshpass or fd0ssh but it wasn't realy working for me. Using expect was working:

Install expect

sudo apt-get install expect

Then you can write a expect script like that

#!/usr/bin/expect -f
# Do not time out
set timeout -1
# Run the SSH comand (As example: open a tunnel for rsync)
spawn ssh -fNL localhost:1873:localhost:873 USER@EXAMPLE.com
# When the passwort prompt is displayed, type and send the password
expect "*?assword:" { send "PASSWORD\r"}
# We need to wayt a little bit
sleep 2

Tuesday, May 22, 2012

According to the GIT FAQ, there is currently no way of adding a empty directory to a GIT repository. But there are workarounds whit placing a dummy file in it and ad this file to the repository. I don't like dummy files, so this is the best solution for me:

Put a file .gitignore in every directory which should be empty. If all other Files in this directory should be ignored add this two lines to the file:

*
!.gitignore

This is specially helpful to add directories which can contain temporary date (eg. tmp dirs).

Tuesday, March 13, 2012

During developing whit PHP, I often run in to just empty page whit out any hint what was going wrong. Using Apache and have set the options "AllowOverride Options" or "AllowOverride All" in the Apache config (done usually by default) you can simply add this lines to the .htaccess file in the directory of the script:

Tuesday, February 21, 2012

During my travel, I was often in places whit bad Internet connections. Specially my uploads of pictures where often interrupted. I wrote a simple script which just executes the same command until it ends whit a success. It is very basic but did the job for me: