Aug 232013
 

Very often from TCL scripts we may want to execute external commands.
But not always they also available, sometime the command that we want to execute may not exist on the respective machine.
One solution is to put the exec command in a catch { exect $your_command $arg1 $arg2 ... } and then to check if it was successfully.

The problem here is that you have to write few lines of code to check if the command is missing, or the arguments passed were wrong.

Other solution, more elegant I think, is to use auto_execok procedure to check if your command really exists, something like bellow:

% set ls_cmd_path [auto_execok ls]
/bin/ls
% puts $ls_cmd_path
/bin/ls
% set ls_cmd_path [auto_execok ls_wrong]
% puts $ls_cmd_path 

%

So, just call the set result [auto_execok $your_command]  and check if the result is not empty string to see if the command really exists.

 

Aug 232013
 

Few days ago I've installed VirtualBox from Oracle on my windows7 machine because I needed a linux where to play with apache webserver.

The instalation was very easy (I assume that internet is available on the host system :D)

  1. Installed VirtualBox
  2. Created a guest machine for Debian
  3. Downloaded Debian Netinstall Image; it is a small CD image which allow ou to install Debian via network. Just google for debian netinst iso , and you should get the latest version.
  4. Tell to VirtualBox to boot first from the downloaded iso file, and "start" the guest machine.
  5. Machine boots and next steps are straightforward: select language, partition disk, select and install packages
  6. The guest machine will then download the needed packages from the internet and will be installed.

Then I made a login to the guest system and play a little with apache, browsing etc...

My expectation was I'll be able to browse the guest apache from the host system.

It does not work by default installation :(... so, I had to read some docs 😀 .

The idea is that on default install the VirtualBox will create an network adapter of type NAT (Network Address Translation). This type of adapter will permit to the guest to browse om Internet via host IP; but it does not allow connections to the guest.

Just stop the guest operating system and in VirtualBox Manager go to Settings->Network and change the network adapter from NAT to Bridged Adapter like in next picture.

network_select_bridged

If you have more than one network adapter on your host system, be sure that in the same window you have selected the proper one. See Name: field, in my case the active one was the Wireless LAN the one that has internet access, so I've selected that one. Be sure that Cable connected checkbox is on.

No other settings are needed.

Click OK and restart your guest operating system.

If you are in a DHCP network (IPs allocated dynamic) do login on the guest operating system and run the ifconfig  command to see what IP was alocated. E.g in my case I got:

>ifconfig

eth0      Link encap:Ethernet  HWaddr 08:00:27:d7:2d:94  
          inet addr:192.168.1.105  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fed7:2d94/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:51 errors:0 dropped:0 overruns:0 frame:0
          TX packets:75 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:14365 (14.0 KiB)  TX bytes:10874 (10.6 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:60 errors:0 dropped:0 overruns:0 frame:0
          TX packets:60 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:23077 (22.5 KiB)  TX bytes:23077 (22.5 KiB)

Then I just go to the host system and browse to http://192.168.1.105/ , and all was fine.

If you are not an a DHCP network (ou are using static IPs), you have to set also the IP on the guest system. The same ifconfig command needs to be used, and it will require root permissions.

More info and details about network adapters available on VirtualBox virtualmanchine cahn be found here http://www.virtualbox.org/manual/ch06.html

Have fun!

Aug 202013
 

One of the most difficult task to do in tcsh is to  redirect the stdout and stderr into separated files. I'm not doing this very often, and because of this I always forget how to do it. Every time when I need to do such a thing I spend tens of minutes trying different combination and reading man/internet pages.

On other shells like bash it is straight forward: my_command > out.txt 2> err.txt  . Such a thing will not work in tcsh, but hey the things are not so complicated. You just have to do (my_command > out.txt ) >& err.txt . Even more, if you want to redirect only the stderr to a file , and want to see what is originally printed on stdout you can do like this: (my_command > /dev/tty ) >& err.txt

Hope that the trick is useful for other visitors who came to this page.

Jun 032013
 

Since year 2000 I'm a big fun of vim editor, in that period I've switched from joe editor to the more powerful vim.

In that period I have used it mostly for PHP programming.
What was not quite OK was the fact that I did not have a PHP help "integrated" into my editor.
What I knew is that the documentation of C/C++ was easy accessible within vim.
In vim when editing C/C++ code just go the the name of a function/structure and press K (SHIFT + k) and magically you will notice the documentation of that word coming up.
The background of this behaviour: when "K" is pressed the vim editor will run the command "man $word" and the output of this command is shown in your editor ($word is the word where the cursor is placed)
The good thing is that the "K" bind key is configurable, all that we have to do is to run set keywordprg=/path/to/my_script in vim (or put it in vim.rc file for needed extensions) and when the "K" key will be press then the vim will run "/path/to/my_script $word".

The next good thing is that on PHP site if you need the documentation for a function or for a statement is enough to put in your browser an URL like http://www.php.net/$a_word (e.g. http://www.php.net/foreach http://www.php.net/printf ), and php.net will give you the documentation page.

So, for PHP extension I've run set keywordprg=/home/mark/my_php_doc and inside /home/mark/my_php_doc I have next couple of lines:

#!/usr/bin/bash
elinks http://www.php.net/$1

It will launch the elinks browser using URL http://www.php.net/$1
Now I have an online PHP help available, always up to date 😉 .

A lot of other things can be done here...
If there is not internet available (hard to believe it nowdays) instead of visiting http://www.php.net/site you can build your own script which will grep some local files and eventually will print the piece of file that you need to stdout (it will be redirected to your editor).
You can also extend the documentation with the function/classes from your own libraries, or for other languages than PHP you can search in the specific directories/files .

This is an old vim tip that I'm using since years, but few days ago talking with some other experienced vim users I've noticed that they were not aware of this feature of vim.
So, I felt the need to share it with other people.

Aug 122012
 

Since years I'm using the putty as ssh client, and I think that it is one of best ever done.
Anyway in the last time I was searching for a SSH client which can handle multiple ssh sessions on the same running instance, to not switch between different windows.

I was looking for something at low cost, but if it is free then it is even better.
Finally I found something: it is mobaxterm from mobatek .
It has what I wanted: tabbed sessions.
If you have multiple connections you do not need to switch between multiple windows, they are tabbed under the same main application.
mobaxterm SFTP tab

    Also, mobaXterm has a lot of other feature, most used be my are:

  • SFTP connection, all he time when you open a ssh connection you will get a SFTP connection too. Continue reading »
 Posted by at 9:55 PM