Samet Kilictas’s Blog

Author Archive

Bash Shell Scripting Tutorial

by Samet Kilictas on Apr.30, 2010, under General, HowTo, Linux

Basics
This tutorial assumes that you already know how to log in to your UNIX machine, bring up the bash shell, and run basic commands such as ls and cat. Getting to this point is fairly easy, but unfortunately this is the level that most users stay at indefinitely. This tutorial is intended to help you start to learn the more advanced features of using a shell, and specifically bash, one of the most powerful shells available.

Please note that most of the command themselves are not explained; you can examine their functionality yourself by either reading their man page, or just experimenting with them to see what they do.

Redirection
Normally programs take input from our keyboard, and display the output to our screens. However, these are just the defaults – UNIX has the ability to redirect the input (commonly referred to as stdin, short for standard input) and output (commonly referred to as stdout, short for standard output).

Here is a simple example: the cat command displays the contents of a file to the screen. But we can redirect those contents to a file using the redirection operator ‘>’, like so:

$ cat myfile.txt
This is the contents of the file myfile.txt
$ cat myfile.txt > newfile.txt
$ cat newfile.txt
This is the contents of the file myfile.txt
$

In effect, we’ve made cat do the same thing as cp, by redirecting the output from the screen to a file. This isn’t terribly useful, but consider another, similar, scenario: cat can take multiple arguments, and it will display the files one after the other. This can be used to append one file onto another and create a new, combined file.

$ cat file1.txt
The quick brown fox...
$ cat file2.txt
...jumped over the lazy dog.
$ cat file1.txt file2.txt > combined.txt
$ cat combined.txt
The quick brown fox...
...jumped over the lazy dog.

Neat, eh?

We can also redirect the input, so that a program takes the contents of a file as if it were typed at your keyboard. cat doesn’t take any input, so let’s use bc, a command line calculator. Normally, you run the program, and it lets you type in calculations such as “2+2″, and then displays the result. But if you have a file which already contains the calculations, you can send it straight to bc – faster and more powerful than cutting-and-pasting the text in with your mouse.

$ cat calc.txt
2+2
$ bc < calc.txt 4 $ 

A final note: you can use two output redirect symbols together – >> – to indicate that you want to append the file, not overwrite it. Hence:

$ cat file1.txt
Contents of file1.
$ cat file2.txt
Contents of file2.txt.
$ cat file2.txt >> file1.txt
$ cat file1.txt
Contents of file1.
Contents of file2.txt.
$

(continue reading…)

VN:F [1.0.6_327]
Rating: 8.0/10 (1 vote cast)
Leave a Comment :, , , more...

if exists syntax in sybase

by Samet Kilictas on Apr.20, 2010, under General, SQL, Tips

Below shows the if exists usage with examples in sybase

If exists (select record)
begin
sql statement 1
sql statement 2
end
else
begin
sql statement 3
sql statement 4
end

Example

Scripts that include constructs like the following may produce errors if the table described in the script does not include the specified column:

if exists (select 1 from syscolumns
where id = object_id("some_table")
and name = "some_column")
begin
alter table some_table drop some_column
end

In this example, some_column must exist in some_table for the batch to succeed.

If some_column exists in some_table, the first time you run the batch, alter table drops the column. On subsequent executions, the batch does not compile.

Adaptive Server raises these errors while preprocessing this batch, which are similar to those that are raised when a normal select tries to access a nonexistent column. These errors are raised when you modify a table’s schema using clauses that require a data copy. If you add a null column, and use the above construct, Adaptive Server does not raise these errors.

To avoid such errors when you modify a table’s schema, include alter table in an execute immediate command:

if exists (select 1 from syscolumns
where id = object_id("some_table")
and name = "some_column")
begin
exec ("alter table some_table drop
some_column")
end

Because the execute immediate statement is run only if the if exists() function succeeds, Adaptive Server does not raise any errors when it compiles this script.

You must also use the execute immediate construct for other uses of alter table, for example, to change the locking scheme, and for any other cases when the command does not require data copy.

VN:F [1.0.6_327]
Rating: 10.0/10 (1 vote cast)
Leave a Comment :, , , , , more...

A common error with GROUP BY Clause

by Samet Kilictas on Apr.16, 2010, under SQL, Tips

A common error with groups is to try to get information which cannot properly be put in a group. For example,


SELECT sales_rep, emp_lname, count( * )
FROM sales_order
KEY JOIN employee
GROUP BY sales_rep

gives the error

column ‘emp_lname’ cannot be used unless it is in a GROUP BY.

SQL does not realize that each of the rows for an employee with a given ID have the same value of emp_lname. An error is reported since SQL does not know which of the names to display.

However, the following is valid:


SELECT sales_rep, max( emp_lname ), count( * )
FROM sales_order
KEY JOIN employee
GROUP BY sales_rep

The max function chooses the maximum (last alphabetically) surname from the detail rows for each group. The surname is the same on every detail row within a group so the max is just a trick to bypass a limitation of SQL.

VN:F [1.0.6_327]
Rating: 10.0/10 (1 vote cast)
Leave a Comment :, , , , , , , more...

IBM RAD 7.5 on Ubuntu Karmic 32 Bit

by Samet Kilictas on Dec.08, 2009, under HowTo

IBM Rational Application Developer
Lets assume you were using ubuntu 9.04 jaunty and now you have upgraded your distribution to 9.10 karmic. Before i get into 9.10 version i had my RAD 7.5 installed and running. Then decided to upgrade my distro. I’ve read an article and futures of karmic distro, that says plenty of packages getting updated. After getting done with upgrade process i tried to run my RAD 7.5 , it was ok for the first time but there were plenty of errors on screen.

First of all when you upgrade your distro, the gcc++ package gets upgareded so libstdc++.so.5 file to libstdc++.so.6 .Unfortunately RAD 7.5 version looks for libstdc++.5.so file on your system. You have to download this file. Download it by using link below;

http://packages.debian.org/stable/base/libstdc++5

Then install this deb package (If you are running on another linux distro you have to place it just next to where your libstdc++.6.so file, you can use “locate libstdc++.so.6″ command to see where your file is). Then copy below bash script and paste it any of your text editor, save it as “run.sh”. From now on, you can use this script to run your RAD 7.5.

#!/bin/bash
export GTK_NATIVE_WINDOWS=1
/where/your/RADis &

After this process your problem should be gone. Have fun.

VN:F [1.0.6_327]
Rating: 0.0/10 (0 votes cast)
Leave a Comment :, , , , , more...

How to enable TCP connections to XServer?

by Samet Kilictas on Dec.07, 2009, under Linux, Tips, Ubuntu


sudo gedit /etc/gdm/gdm.schemas

find:

<schema>
<key>security/DisallowTCP</key>
<signature>b</signature>
<default>true</default>
</schema>

shift from true to false:

<schema>
<key>security/DisallowTCP</key>
<signature>b</signature>
<default>false</default>
</schema>

VN:F [1.0.6_327]
Rating: 10.0/10 (1 vote cast)
Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...