Friday, January 22, 2010

Creating ico files

To put it simply, this don't work
http://msdn.microsoft.com/en-us/library/ms997636.aspx

This works.
http://egressive.com/tutorial/creating-a-multi-resolution-favicon-including-transparency-with-the-gimp

Case closed. Wasted 1/2 day following the official advise thinking I did something wrong.

Automating ssh, ftp, scp

A really good way to automate ssh, ftp or scp is to use "Expect" (http://expect.nist.gov/). To kick it off, just use "autoexpect" which records your key stroke into an expect script and you just need to run the expect script and it can be cron. Easy as that.

Then again, if everything is so easy, we would lose our jobs. More often than not, there is some customization required. Expect is based on tcl, so if you are familiar with tcl, you are good. If not just search for what you want to do in tcl and usually there should be someone who has already came across the problem and someone else has helped.

In my case, I need to scp all the files in one directory into a remote server. In autoexpect, I used the following command.

autoexpect scp /somedir/* user@remoteserver:/somewhere/

The problem is that the /somedir/* is expanded to list out all the files in the directory. In the generated expect file it looks like this

spawn scp /somedir/f1 /somedir/f1 /somedir/f3 user@remoteserver:/somewhere/

Now we know that the files will change so this won't work. In this case, a bit of scripting is needed:

set files [glob -directory /home/koopt/user_backups/ *]
set source ""


foreach f $files {
  set source "$source $f"
}
spawn scp $source user@remoteserver:/somewhere/

The function "glob" will list out all the files in full path and we just loop through the files to get a long list of files to scp to the remote server.