Categories

Mass creation of symlinks

03rd September 2010

Today I was installing a new server. Downloaded the latest version of Ruby Enterprise Edition and installed it successfully. As I didn’t have any other ruby sitting in my system, I decided to symlink all of ruby executables from /usr/bin. But how do I do that? The first, obvious and sub-optimal way would be to issue “ln -s” command for each file. “That’s too much work” – I said and started googling.

Long story short, this is the solution I came up with:

find /opt/rubyee/bin/ -type f -name '*' -printf '%f,' | xargs -I '{}' -d ,  sudo ln -s /opt/rubyee/bin/{} /usr/bin/{}

A bit of explanation:

find /opt/rubyee/bin/ -type f -name '*' -printf '%f,'

This command finds all (-name ‘*’) files (-type f) in /opt/rubyee/bin and list their names, separated by comma (-printf ‘%f,’). Then the resulting output is passed to the next command.

xargs -I '{}' -d ,  sudo ln -s /opt/rubyee/bin/{} /usr/bin/{}

It basically splits its input stream by comma (-d ,) and executes “sudo ln“, replacing every occurence of {} in its arguments with actual filename.

The resulting command surely seems scary for a novice Linux admin, who I am. Probably I could utilize -exec parameter of the find, but this worked well enough for me. Also, if I did it manually, it actually would be several times faster. But hey, are we programmers or not? :-)

Tags:

I am trying to make a small Silverlight control that talks to PHP server. Sometimes problems arise and I have to deal with them myself, since there’s not much information on this topic in the internet. Trouble of the day is:

The remote server returned an error: NotFound

when trying to make simple POST request to a PHP page. I’ve spent half a day diagnosing this problem. And solution was found entirely by chance, because exception messages weren’t helping in any way. I mean, I was always getting abovementioned error message, without any details (what host, what page, request parameters, etc). But enough of complaints, let’s proceed to the solution. The troublesome code was this one:

var _request = (HttpWebRequest)WebRequest.Create(_svcUri);
_request.Method = "POST";
_request.ContentType = "application/json";
_request.Headers["sid"] = SessionID ; // <==== this line

SessionID was null at the moment and this made HttpWebRequest so pissed off that it even wouldn’t send request header to the server ! And because of this, Fiddler was completely useless here. After adding necessary check, everything started working like a charm.

I installed this copy of WordPress this evening and decided to add to Live Writer. But I’ve ran into problem almost immediately. While trying to auto-detect my editing style, blog name and who knows what else, Live Writer kept annoying me with this message: "Invalid Server Response – The response to the blogger.getUsersBlogs method received from the weblog server was invalid".

I hit Ctrl-Ctrl (very handy shortcut of Google Desktop, that summons search bar) and pasted the error text there. First, I came across this article. I followed every step in it (some of them twice :-) ), but it didn’t help. So I kept searching.

Then I found this interesting site. Performing this step didn’t help me either. I have installed Fiddler and it finally shed some light on the problem. There was an error while requesting xmlrpc.php (which is used by external systems, such as WLW, to talk to WordPress).

Warning: include_once(/home/tulentse/public_html/blog_technical/wp-includes/class-IXR.php) [function.include-once]: failed to open stream: No such file or directory in /home/tulentse/public_html/blog_technical/xmlrpc.php on line 55
Warning: include_once() [function.include]: Failed opening ‘/home/tulentse/public_html/blog_technical/wp-includes/class-IXR.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/tulentse/public_html/blog_technical/xmlrpc.php on line 55
Fatal error: Class ‘IXR_Server’ not found in /home/tulentse/public_html/blog_technical/xmlrpc.php on line 108

I navigated to that file and saw that the name is in lower case (and case matters on Unix-based systems). It was joint effort of me, who checked "Convert filenames to lower case" option and Total Commander who did what I told him.

Now everyone’s happy :-)