Friday, September 24, 2004

ssh

To setup OpenSSH's sshd, you must first set up the keys used:

cd /etc/ssh
ssh-keygen -b 1024 -f ssh_host_key -t rsa1 -N ''
ssh-keygen -b 1024 -f ssh_host_rsa_key -t rsa -N ''
ssh-keygen -b 1024 -f ssh_host_dsa_key -t dsa -N ''


Thursday, September 23, 2004

common perl mistakes -1

$var2 = chomp($var1);

isn't going to put the chomped $var1 in $var2

perl error

Reference found where even-sized list expected at ./test.pl line 39.

-- you get this error when you try to initialize a hash like below

%hash_name = {};

from http://linux.about.com/library/cmd/blcmdl1_perl5005delta.htm

Reference found where even-sized list expected
You gave a single reference where Perl was expecting a list with an
even number of elements (for assignment to a hash). This usually means
that you used the anon hash constructor when you meant to use parens.
In any case, a hash requires key/value pairs.

%hash = { one => 1, two => 2, }; # WRONG
%hash = [ qw/ an anon array / ]; # WRONG
%hash = ( one => 1, two => 2, ); # right
%hash = qw( one 1 two 2 ); # also fine


Curly brackets are used to construct anonymous hashes. Their result is
a reference to that hash. So with %f = {} you're trying to assign a
reference (one item) to a hash. However, hashes are initialized with
lists which must have an even number of elements. Hence the warning.
The proper way to initialize an empty hash is with an empty list, which
is why %f = () works.


Tuesday, September 21, 2004

scanf

From: http://webcourse.cs.technion.ac.il/234117/Spring2004/ar/faq_Homework.html

>>I'm having a problem using scanf. After I enter the username, the following scanf reads the "enter" I clicked. What should I do?

Instead of writing scanf("%c") you can write scanf(" %c") (with a space before %c), and it should work better. The space before the "%c" will read all white spaces (newline, tab and space) and the first non-white space will be read into the "%c". Using the scanf this way will prevent the scanf from reading the "ente

Sunday, September 19, 2004

find /tmp -type f -name "*.gz" -exec tar -xvzf '{}' ';'
find ./ -name "*.gz" -exec tar -xvzf {} \;

#### to exclude files in directory results
find . -name results -prune -o -type f -name "*.bc"

ls -lai | grep -v imp_file | xargs rm -f