Sunday, March 16, 2008

some fun with terminals

Some fun with terminals
There are two tools that can be usefull when working in console :
- script
- screen

1. script

script is a nice program that let you monitor in one or
more terminals what you type in another terminal.

Example:
- Open two X terminals in your X session or use the Linux
ttys (ctrl + alt + F1-6)

- On one terminal, type :
Code:
cd ~
mkfifo output
script -f output
- On another terminal (or more), type :
Code:
cd ~
cat output

- Then return to the first terminal and execute any
command you like (ls, cd, ping...)

The output should be appear on every terminals where
you cat output fifo.

- Exit script session by typing exit command in the first
terminal (the one which you started script command)

man script for more infos


2. screen

screen is a terminal screen manager (like a window manager
but for consoles)

Example:
- In a terminal, type : screen
screen is now started, it has opened one screen, you should
see the prompt of your shell, waiting for commands

- Name this screen with typing : [ctrl + a], then A (note that
A is uppercase, so you may need to type:
[ctrl +a], then [shift +a]
Erase the default title using backspace key and name it whith
any name you want, say "Shell 1", press key.

- Create a new screen with : [ctrl + a] [ctrl + c], name it
([ctrl + a], [shift + a]), say "Shell 2"

- To switch between these 2 screens, type [ctrl + a], then ["]
(double quote key), you should see a list of all your screens
To enter on one, just select it with the top/bottom arrow keys
and press

- To exit screen, just type exit in all your opened screens

Tips for ssh session :
Say you run a command that take long time to complete
(say updatedb or a system upgrade), you can detach your
screen, exit ssh session, let the command run on the
remote host and return to the screen later :

- ssh to your remote host, run screen, run your command,
then type : [ctrl + a], [shift + d], [shift + d]

You now are now logout of your ssh session, screen in
remote host is detached so it keep running your command

To return to your screen, ssh into your remote host, then
use : screen -r

You are now in the screen showing output of the command
you issued before.

man screen for more infos

create mysql user and give permissions to access

$cmd:create user username


$cmd:grant all privileges on *.* to 'username'@'ipadress' identified by
'password' with grant option;

'*':the 1st '*' represents which databases you want to acces

'username': for which username you want to give permissions
'ipaddress': from which ipaddress you want to access, you can put localhost for local systema and '%' for all the systems in the network.(you can give both one at each time)

'password': for which password you want access

apache configuration in fc5

apache cofiguration in fc5 to see html scripts on your own system

Open the file httpd.conf (generally in /etc/httpd/conf/httpd.conf or
locate it by running locate httpd.conf).

-->Find this line 'UserDir public_html'(generally around 355-365 line) and
uncomment it

-->Find 'UserDir Disable'(a few lines above the previous one) and comment
it.

-->Find 'ScriptAlias /cgi-bin/ "/var/www/cgi-bin" and uncomment it if it
is commented.(around 555-565 line)

-->In the code segment that begins like this ...(immeadiatley below the
above one)



change the line 'Options None' to 'Options ExecCGI'

-->Find the line 'AddHandler cgi-script .cgi' and uncomment it.

-->And include this segment of code to enable
execution of cgi scripts in ur /home//public_html/cgi-bin (for
that matter any directory of the path you mention).



AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all






AND MOST IMPORTANTLY.. Dont forget to start your http server,as simple as
that..

root@localhost#service httpd start

now goto http:///~/cgi-bin

or http:///cgi-bin (the default)

mysql backup and restoring databases

mysql dump
from database to file:

$cmd:mysqldump -u username -p databasename > filename.sql

it will ask for password

from file to database:

$cmd:mysql - u username -p databasename < filename.sql



More detailed backup:


Tacking full backup of all the tables and data also:

$cmd:mysqldump -u username -p databasename > filename.sql

Taking the backup of table structures only:

$cmd:mysqldump -u username -p --no-data databasename > filename.sql

Taking the backup data only:

$cmd:mysqldump -u username -p --no-create-info databasename > filename.sql

But the restoring is same for any of these backup methods

log into another linux system with using password only once

$cmd:ssh-keygen -t rsa
press enter it will ask for customization
$cmd:scp ~/.ssh/id_rsa.pub username@ipaddress:.ssh/authorized_keys2

it will ask for password enter password
eg:
save passwd for 200 or 205:

$cmd:scp ~/.ssh/id_rsa.pub anjaneyavsk@192.168.36.205:.ssh/authorized_keys2