Search This Blog

Showing posts with label links. Show all posts
Showing posts with label links. Show all posts

Thursday, March 12, 2020

Bash and Arrays

Short reminder for my 'extended memory' on how to deal with lists in bash.

To define:
  • a list (an array): declare -a list
  • a dictionary (an associative array): declare -A dict
To use an array in loop: for item in ${list[@]}

Now the best, at least for scripts testing:
To print a whole array: declare -p list (please note, no "$" before list name).


Found at https://www.tutorialkart.com/bash-shell-scripting/bash-array/


Saturday, December 31, 2016

Control terminal name and comment block in VIM

Somewhere (I think it was Stackoverflow) I found simple command to control the name of terminal from commandline which works very nice with iterm2 tabs on MacOSX and decided to add to my zsh environment this function:

termname() {
 echo -en "\e]1; $1 \a"
}
 

And if we are saying about Stackoverflow one of the most useful Vim suggestion I've ever found is this instruction to comment/uncomment a multiple lines in VIM.

Saturday, December 28, 2013

Space War

Let say it is a late Christmas present for Science Fiction fans. Especially ones who like a lot of science in SF. Two articles discussion how space warfare can look. Have fun.

Sunday, February 05, 2012

CakePHP tutorials on TuxRadar

LinuxFormat presented a some time ago interesting tutorials to CakePHP. What even more interesting their share materials on TuxRadar webpage. The only problem I found is lack of some kind of list of contents, so I made one:

  1. CakePHP Tutorial: Build Web Apps Faster
  2. CakePHP Tutorial: Storage, Baking and Slugs
  3. CakePHP Tutorial: Build a file sharing application
  4. CakePHP Tutorial: Build a bookmark site

BTW. IF you hit this page you might be also interested in Practical PHP Programing tutorial from the same page.

Tuesday, January 11, 2011

Expect, telnet and Dell switch

Recently I've tried to find a way to obtain MAC addresses of computers attached to a Dell Switch. I've found that i.e. show bridge address-table ethernet 1/g3 returns  MAC addresses behind the port 3. I found small problem - it's not so easy to query all ports (or a chosen set of ports). Therefore, I decided to use expect. You can find the script below.
It connects to a switch run the command and finally print a mac address in the format with ':' between number doublets.
However, there are two issues. I don't know how to avoid sending everything to the standard output. Moreover, if there are more than one MAC address connected to the port (i.e. virtual machines), only first address will be print on the bottom of the output. To be precise the address  appears in the line 6 of output (see line started with set temp_mac).


#!/usr/bin/expect -f

set timeout -1

set machine [lindex $argv 0]
set port [lindex $argv 1]
set command "show bridge address-table ethernet 1/g$port\n"

#Connect to the server
spawn telnet $machine 

expect "User:"
exp_send "admin\r"
expect "Password:"
exp_send "myXEN\r"
expect "?*>"
exp_send "enable\r"
expect "?*#"
exp_send $command
expect "?*#"
set temp_mac [ lindex [ lindex [ split $expect_out(0,string) "\n"] 6] 1]
exp_send "exit\r"
exp_send "quit\r"

puts "\n"

# Creating mac address in DHCP format (with ':')
set mac [ string range $temp_mac 0 1 ]
append mac "."
append mac [ string range $temp_mac 2 6 ]
append mac "."
append mac [ string range $temp_mac 7 11 ]
append mac "."
append mac [ string range $temp_mac 12 13 ]

puts  "$machine/$port:  [ string map  {. :} $mac]"

exit
Oh one more thing. To make a list of all following it's good to run the script in loop and the following one should be good base to start with.

for ((i=1;i<48;i++)) do mac-dell.expect esw44-1 $i| grep "esw44-1/$i"; done

Thursday, January 07, 2010

Short (mostly shell) fomulas

If you hit this website looking for a Linux/shell/UNIX related advice you might want to visit my identi.ca account. I post "short, magic", Linux formula there now. You know something like:

How to split lines in ?
s/\,/,[ctrl-V][Enter]/g
where [ctrl-V][Enter] - means type Ctrl+V and next Enter (you should see s/\,/,^M/g)

Monday, June 22, 2009

one for AWK and one for SVN

Another two useful one liner. First awk. Sometimes you need to grab last "element" of lines in a file which has different numbers of spaces (or other separator). In such case use variable $NF (or $NF-1, $NF-2...). Good example for such situation might be apache log file, where user agent description is a string with various number of spaces, so it's hard to get columns after that. But you can use something similar to:
 tail bo-access_log.2009-06-22 | \
awk '{print "size:\t"$(NF-1) "\t time:\t" $NF}'
In the example log file the time is the last and size of file next to last field. Of course you can type it in one line. But Then you have to remove '\' character from end of first line. Second advice is related to SVN. I found reverting last submitted changes quite not clear there. Revert works only with no committed changes, so I used the command similar to below one.
 svn merge -r HEAD:{2009-06-21} .
The example reverts everything what has been submitted between 21st June 2009 and 'now'. However, today I found that PREV 'variable', so the following command should do I had wanted to achieve. Interesting how could I missed it?
 svn merge -r HEAD:PREV .
And one more update. In petke comments to this entry in Aral Balkan blog I found another one liner, which looks event easier:
svn update -r 2689

Tuesday, March 10, 2009

My first Perl script

It's nothing big, but it's the first one and, as Perl is write only language, I'd better add the short description. The script takes a list of files passed as arguments to the command; reads all lines (http addresses) from them and creates the list of unique domains names.
#!/usr/bin/env perl

%seen = ();
foreach (@ARGV)
{
open (LFILE,"$_");

for $line ()
{
       @sline=split(/\//,$line);
       print ("@sline[2]\n") unless $seen{@sline[2]}++;
}

close LFILE;
}
Perl tutorial from tizag.com was helpful.

Tuesday, November 25, 2008

BigPicture

I don't know how I might not to add this earlier but I didn't. The Big Picture it's a on-line addition to Boston Globe (I guess it only on-line, but I don't reader Boston Globe, as I'm leaving in proper Cambridge, at least at the moment). I saw it first time on Bad Astronomy Blog. That story was about picture of our sky but made from above. The pictures were amazing, but what more important that Big Picture brings new great pictures month after month. It's quite interesting how many of them are space/astronomy related, i.e. this one:

Wednesday, June 04, 2008

Yet Another Gnuplot Script

I'm preparing presentation for the Public Defence of my PhD thesis. I'm creating few plots and of course I'm using gnuplot for them. One of plots is seems to be really simple: three 'columns' each in other colour, but it took me few hours to make it. I'm glad that I finally did it so I'm sharing my scripts with you (I needed Postscript for Greek's symbols):
set term postscript eps enhanced color
set output "nlo-rhb-cc.eps"
set ylabel '{/Symbol b} [10^{-30} esu]'
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth
unset xtics

plot [-0.5:.7][-15000:0] "cc.csv" using 1 ti col, '' using 2 ti col, '' using 3 ti col
If you would like to try use the data below: and data:
HF/FF MP2/FF CCSD
-14720.51945800 -6960.7083277 -10843.140 
BTW. I noted three new interesting website related to the gnuplot:

Thursday, May 15, 2008

Ian Foster blog

When I was preparing to the exam from GRID computing one of me friend sent me a link to the Ian Foster blog, and I think that it is great that you can follow thoughts one of the GRID fathers. At the moment he is at the "Open Source Grid & Cluster Conference". It is very interesting that you can grab pdf/videos/ppt from all point of programme.

Tuesday, April 29, 2008

Sed one liners

I'm using this set of sed one liners very hardly. Today I found that I hasn't added it to my blog so I cannot find it easily. (You know I use this blog as a some kind of memory extension ;) I was trying to find sed command capitalized a variable, I couldn't find it at mentioned page. Farther searching pointed to very interesting thread at Unix .com forum. The was script doing something similar in python, perl, sed and awk. I chosen perl:
echo $myvar | perl -p -e '$_ = ucfirst'
However, python looks also nice:
echo $myvar | python -c "print raw_input().capitalize()"
Awk one is also nice, but a bit more complicated (one line):
echo $myvar |awk '{(sub("^.",substr(toupper($1),1,1),$1)); print }'

Monday, March 10, 2008

Unix tips

Today I would like to share two link related to UNIX. The first one is IBM tips how learn 10 good UNIX usage habits. The second one is The ultimate collection of UNIX cheat sheets by Scott Klarr.

Thursday, February 21, 2008

4 blogs - 4 maybe not so different subject

I would like to present 4 interesting blogs from 4 different area:
  1. Bash Cures Cancer, how it is easy to guests, is a nice blog mostly about Bash tips&trick. However, you can also find infos about other FOSS.
  2. I'm not sure if you can call Molecules of the Month @ 3DChem a blog. I think it's older than idea of blog (it has been started in 1996). The subtitle (molecules of the month) indicates one molecule per month, but molecules have been added in random manner - no molecule between October 2007 and January 2008 and 4 in January. Anyway, the choose of molecules are quite good and the additional information can be really useful.
  3. Bad Astronomy Blog is a good blog about astronomy. I visited it first because of this entry, especially because of this picture. Just be aware that from time to time there are some politics/religion related entries.
  4. Finally, Online Video Streaming Archive is looking promising place where Nature (one of the best/the best scientific journal on Earth ;) presents streaming videos that feature interviews with scientists behind the most important present research.

Sunday, December 09, 2007

3D in Linux

There is a very interesting overview of present state (Nov 2007) of 3D graphic card drivers on Mitch Meyran's blog.

Wednesday, December 05, 2007

Two chemical links

This time two links to websites related to chemistry.
  • The Supercomputing Institute from University of Minnesota prepared kit of Tutorials for Computational Chemistry and Physics Sciences.
  • Vitalii Vanovschi created the website with many important chemical informations.

Friday, November 02, 2007

OpenGL and Windows

I'm starting to me more interesting in 3D graphic. Looking for some information about OpenGL on Windows I found Lucian Wischik old webpage. Maybe information collected on it isn't the latest news, but at least one thing is quite interesting. There is a register key which keep information about which library provided OpenGL functionality on your computer. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\OpenGLDrivers. The another interesting finding is OpenGL Extension Viewer provided by RealTech-Vr. It works on Windows, MacOSX and under Wine.

Thursday, March 01, 2007

10 nice shell command

Here you can find 10 nice, but not very other using shell command. Personally, I was using bc and lsof.

Wednesday, December 06, 2006

Vim's colorscheme

I've found nice site with sample of Vim's colorschemse. I miss only python samples.

Saturday, November 18, 2006

The Python Challenge

I nearly become addicted. To what? To Python Challenge. It is a set of puzzle which can be resolved with Python (you can use other language, but it is design for Python). I don't remember when I have so much fun. It is great think if you what to learn Python or just test your skills. It is my 50th note and I started write this blog 1 year and 3 days ago!