Chủ Nhật, 15 tháng 7, 2012

Determine used and free space in a tablespace

SELECT t.tablespace,
       t.totalspace AS " Totalspace(MB)",
       ROUND ( (t.totalspace - fs.freespace), 2) AS "Used Space(MB)",
       fs.freespace AS "Freespace(MB)",
       ROUND ( ( (t.totalspace - fs.freespace) / t.totalspace) * 100, 2)
           AS "% Used",
       ROUND ( (fs.freespace / t.totalspace) * 100, 2) AS "% Free"
  FROM (SELECT ROUND (SUM (d.bytes) / (1024 * 1024)) AS totalspace,
               d.tablespace_name tablespace
          FROM dba_data_files d
        GROUP BY d.tablespace_name) t,
       (SELECT ROUND (SUM (f.bytes) / (1024 * 1024)) AS freespace,
               f.tablespace_name tablespace
          FROM dba_free_space f
        GROUP BY f.tablespace_name) fs
 WHERE t.tablespace = fs.tablespace
ORDER BY t.tablespace;

Thứ Sáu, 13 tháng 7, 2012

Config FTP server

SUN Solaris FTP
SUN Solaris comes with ftp daemon based on WU-FTPd Washington University project.
While not being very enthusiastic about its vulnerabilities discovered over the years and being rather
abandoned by its developers ,still it comes by default and as long as Sun ok with that it is ok with me too.
Below I will shortly introduce configuring it for local user access as well as anonymous one.

By default FTP daemon (in.ftpd) is disabled. Here is the initial state you have it :
root@Solaris# svcs ftp
STATE STIME FMRI
disabled 7:21:44 svc:/network/ftp:default
As ftpd is inet managed daemon more information can be queried from inetadm:
root@Solaris# inetadm -l svc:/network/ftp:default
SCOPE NAME=VALUE
name=”ftp”
endpoint_type=”stream”
proto=”tcp6″
isrpc=FALSE
wait=FALSE
exec=”/usr/sbin/in.ftpd -a”
user=”root”
default bind_addr=”"
default bind_fail_max=-1
default bind_fail_interval=-1
default max_con_rate=-1
default max_copies=-1
default con_rate_offline=-1
default failrate_cnt=40
default failrate_interval=60
default inherit_env=TRUE
default tcp_trace=FALSE
default tcp_wrappers=FALSE
default connection_backlog=10
Insecure you say , well , you are right – let’s sharpen it a bit.
Enable more detailed logging.
root@Solaris# inetadm -m svc:/network/ftp:default tcp_trace=TRUE
root@Solaris# inetadm -l svc:/network/ftp
SCOPE NAME=VALUE
name=”ftp”
endpoint_type=”stream”
proto=”tcp6″
isrpc=FALSE
wait=FALSE
exec=”/usr/sbin/in.ftpd -a”
user=”root”
default bind_addr=”"
default bind_fail_max=-1
default bind_fail_interval=-1
default max_con_rate=-1
default max_copies=-1
default con_rate_offline=-1
default failrate_cnt=40
default failrate_interval=60
default inherit_env=TRUE
tcp_trace=TRUE
default tcp_wrappers=FALSE
default connection_backlog=10
When execution option –a is given (and it is by default) then ftpd will consult /etc/ftpd/ftpaccess
file for additional restrictions and tweaks. Here are the few that are worth enabling.
Uncomment following lines to have more verbose logging available:
log transfers real,guest,anonymous inbound,outbound
xferlog format %T %Xt %R %Xn %XP %Xy %Xf %Xd %Xm %U ftp %Xa %u %Xc %Xs %Xr
Make sure these changes are applied
root@Solaris# svcadm refresh svc:/network/ftp:default
Configure anonymous access.
All the configs so far will allow only local valid users to connect by ftp and be automatically
placed in their respective home directories. To allow anonymous ftp access with dedicated chrooted for that folder there is a special set of tools to use. Actually it is just one script that does all the hard work behind the scenes – creates ftp user, creates directory tree , sets up needed permissions, sets up chrooted environment for the anonymous ftp user.
 
root@Solaris# ftpconfig /export/home/ftp_pub
Updating user ftp
Creating directory /export/home/ftp_pub
Updating directory /export/home/ftp_pub
That is all, now you can login anonymously and download anything from /export/home/ftp_pub/pub directory. To also allow upload there , change the upload option in “/etc/ftpd/ftpaccess” and set accordingly permissions on the Solaris level for the directory pub (777)

root@Solaris#chmod 777 /etc/ftpd/ftpaccess

upload class=anonusers * /pub yes
#upload class=anonusers * * no nodirs
And finally enable it
root@Solaris# svcadm enable ftp
 

Thứ Sáu, 6 tháng 7, 2012

Using the vi Text Editor in Solaris 9

In the world of Solaris, most files are plain text without fancy typographic material, whether text, shell scripts, Web pages, or even C programs. No bold, no multiple font colors, no included graphics. As a result, most Solaris users use vi, a powerful (albeit tricky to learn) text-only editor that enables you enter and modify text quickly. With vi, you must do everything — from cursor motion to search and replace — from the keyboard.

Understanding modes

Perhaps the most puzzling aspect of vi is that it is a modal editor. These are the two modes of operation:
  • Insert mode: If you're in insert mode and type an x, the letter is added to the document at the current cursor point.
  • Command mode: If you're in command mode, the x command causes the letter under the cursor to be deleted, not added.
Fortunately, there's a trick to starting up vi that enables a mode display function on the bottom line of the screen. This display quickly tells you whether you're in insert or command mode. Rather than specify the show mode feature manually each time you start vi, open a terminal window and type the following:
echo "set showmode" >> ~/.exrc
Do that once, and you've created a custom preferences file for vi (yes, it should be called .virc, but that's a long story). You don't have to ever think about it again.

Starting vi

You can start the vi editor from the command line several ways:
  • Type vi on the command line:
$ vi
  • Specify the name of an existing file to edit or a new file to create:
$ vi my.new.file
  • You can also specify a list of filenames if you want. You can finish editing the first file, and then move to the second, and so on to modify a batch of files in sequence.
Start vi by specifying the name you want to create:
$ vi ashley.travels.txt
The File, Edit, View, and other menus are for the terminal application, not vi. The vi program has no fancy interface elements, just whatever you type at the keyboard.
There's no menu at the bottom, just a cursor at the top-left corner and a bunch of tilde symbols (~) running down the left side. The lines prefaced with tilde symbols are placeholders, not part of the file. They're beyond the end of the file being edited.

Entering text

By default, the editor starts out in command mode: Type an x, and you'll hear a beep as the editor tells you that there's nothing to delete. You can move into insert mode several ways, depending on where you want to insert text. In fact, vi has dozens and dozens of commands.
Following are a few some basic commands:
  • To insert just before the current cursor location (where the flashing block is sitting), press i.
  • To insert just after the current cursor location, use a to append text.
  • To insert just above the current line by creating a new blank line, use O (capital o).
  • To insert into a new blank line just below the current line, use o (lowercase o).
Jump into this by pressing i and typing the following:
Gulliver's Travels is the most well-known work of Irish writer Jonathan Swift, famous for his work as a novelist, essayist and satirist. You Betcha!
To make this interesting, add a few random nonsense characters at the end of what you type in.
Notice that the bottom-right corner of your screen says INSERT MODE. That's the show mode feature giving a visual clue of what mode you're in.
To leave insert mode and get back to command mode, press the magic key, Esc. Intelligently, the Esc key has no function in command mode. You can press it any time you want to be in command mode and aren't sure what mode you're in. It just beeps.

Moving in the file

Because vi has no scroll bars and no mouse support, it has a set of keys that you can use in command mode to move around.
On Solaris, you can also use the arrow keys on your keyboard unless you're connected remotely, in which case they may or may not work.
The four key movement keys are h, j, k, and l:
  • h moves one character to the left.
  • j moves one line down.
  • k moves one line up.
  • l moves one character to the right.
Try using these four keys to move around. If these letters start to appear in your document, you're still in insert mode and need to press the Esc key.
  • You can move one word at a time with w or b, depending on whether you want to move forward one word or backward one word.
  • You can jump to the beginning of the line with 0 (zero) and to the end of the line with $.
  • To move page by page, when the file is sufficiently large to have pages of text, use
• ^F to move forward a page
• ^B to move back a page
• ^D to move down half a page
• ^U to move up half a page
  • You can jump to the first line of the file with 0G (zero followed by G) and to the end of the file with G by itself.
Use motion keys to move to the first letter of the extraneous stuff you added to the file. Now press the x key a few times. Each time you press it, you should see the letter under the cursor deleted and the text slide left to fill the now open hole.
Finish up the delete process so that there are no stray characters. Then use the a append function to add a few carriage returns immediately after the period ending the sentence. The cursor should now be on the last line, with at least one blank line separating it from the text in the file.

Including other files

To include the contents of another file, you need to jump to the vi command line.
  • You do this by typing : , at which point the cursor immediately jumps to the bottom-left corner of the screen.
    Type in the following command:
r gullivers.travels.txt
  • After pressing Enter, the contents of the file are injected into the buffer, exactly as you saw in the GNOME Text Editor and CDE Text Editor.

Saving files

The final step on this journey is to save the new file. You started vi with the new filename. To save the file with that name, type one of these commands:
  • :w writes the file and stays in vi.
  • :wq writes the file and quits vi.
ZZ writes out the file if it has changed and then quits, without the command line (:) sequences.
If you entered more than one file, use :w to write out this file and then :n to move to the next file on your list.
To quit and discard the changes that you have made, add a ! to the end of the command, like this:
:q!

Source:  http://www.dummies.com/how-to/content/using-the-vi-text-editor-in-solaris-9.html

Sync Date/Time on Solaris with NTP Server

"Manually" set the clock correctly just once

Sample: ntpdate -b clock.example.org timekeeper.sample.com
 
Set the clock correctly on every boot up
Create the ntp.conf file.
To activate the ntpd daemon, the ntp.conf file must first be created.

# cd /etc/inet
# cp ntp.client ntp.conf

 Edit the ntp.conf file.

 
Sample: 
driftfile /etc/ntp.drift 
# public NTP servers we sync to:  (use these 2 lines ONLY on ntp1 and 
ntp2!)
server clock.example.org
server timekeeper.sample.com

Thứ Năm, 5 tháng 7, 2012

Check Oracle run Cluster Mode or not

SET SERVEROUT ON

DECLARE
BEGIN
    IF DBMS_UTILITY.is_cluster_database
    THEN
        DBMS_OUTPUT.put_line (
            'Your database is running in Parallel server mode');
    ELSE
        DBMS_OUTPUT.put_line (
            'Your database is NOT running in Parallel server mode');
    END IF;
END;