Kernel
The linux kernel is the most important part or in order word called the heart of the linux operating system. It is the piece of code that manages both hardware and software components and communicates between them. It manages memory, processors, I/O devices with any applications and decides which applications will use hardware resources.
Shell
On your windows machine you have seen command prompt (command.com or cmd.exe) where you type command like ping, ipconfig etc. Similarly, on linux there is such prompt where you can type command and that prompt is called shell. In order to define shell we can say shell is an interpreter that interprets commands as typed from a keyboard or from a text script.
The shell is provided in order to interact with the computer systems. Shell itself is not part of the kernel, but it uses kernel to executes commands.
There are various types of shell and can be broadly defined into four categories.
1)Bourne like shell(sh): Almquist shell (ash), Bourne-Again shell (bash), Debian Almquist shell (dash), Korn shell (ksh), Z shell (zsh) falls into bourne like shell category.
2)C shell like (csh): TENEX C shell (tcsh) falls within this category.
3)Non traditional shell: es shell (es), scheme Shell (scsh) falls within this category.
4)Historical shell: Thompson shell (sh), PWB shell or Mashey shell (sh) falls within this category.
In order to know all available shells in your system issue, cat /etc/shells
On my system,
# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
To find out current shell you are using issue, echo $SHELL or ps $$
On my system,
# ps $$
PID TTY STAT TIME COMMAND
4593 pts/0 Ss 0:00 -bash
# echo $SHELL
/bin/bash
Shell Script
Shell script is a plain text file which contains a series of commands. In this case instead of running command one by one we can store all commands in a script and we execute the script. It is similar to a batch file in MS-DOS.
Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts
Tuesday, April 21, 2009
A simple shell script to check whether user is root
In many case inside your shell script you need to check whether the user who runs the script is root or not because based on the user you might need to take necessary action inside your shell script.
Following shell script might help you in this case.
Way 01: With system variable $LOGNAME
As echo $LOGNAME show the currently logged in user show we can use this variable to determine whether it is root user.
1)create script
# vi test_root.sh
if [[ $LOGNAME = "root" ]]
then
echo "You are root user"
else
echo "You are $LOGNAME user"
fi
2)Grant execute permission.
# chmod +x test_root.sh
3)Test it by running as root.
# whoami
root
# ./test_root.sh
You are root user
4)Test it by running as oracle user.
# su - oracle
$ whoami
oracle
$ ./test_root.sh
You are oracle user
Way 02: As system variable $UID:
As system variable $UID for root user is zero so we can use that in order to determine whether user is root.
1)create script
# vi test_root2.sh
if [[ $UID = "0" ]]
then
echo "You are root user"
else
echo "You are not root user"
fi
2)Give execute permission.
# chmod +x test_root2.sh
3)Test it by running as root user.
# ./test_root2.sh
You are root user
Way 03: With the command whoami
With the command whoami you can check the user who is logged in. So you can use that in your script.
1)Create script
# vi test_root3.sh
if [ `whoami` = "root" ]
then
echo "You have logged on as root"
else
echo "You are not root user"
fi
2)Grant execute permission.
# chmod +x test_root3.sh
3)Test the script by running it.
# ./test_root3.sh
You have logged on as root
Following shell script might help you in this case.
Way 01: With system variable $LOGNAME
As echo $LOGNAME show the currently logged in user show we can use this variable to determine whether it is root user.
1)create script
# vi test_root.sh
if [[ $LOGNAME = "root" ]]
then
echo "You are root user"
else
echo "You are $LOGNAME user"
fi
2)Grant execute permission.
# chmod +x test_root.sh
3)Test it by running as root.
# whoami
root
# ./test_root.sh
You are root user
4)Test it by running as oracle user.
# su - oracle
$ whoami
oracle
$ ./test_root.sh
You are oracle user
Way 02: As system variable $UID:
As system variable $UID for root user is zero so we can use that in order to determine whether user is root.
1)create script
# vi test_root2.sh
if [[ $UID = "0" ]]
then
echo "You are root user"
else
echo "You are not root user"
fi
2)Give execute permission.
# chmod +x test_root2.sh
3)Test it by running as root user.
# ./test_root2.sh
You are root user
Way 03: With the command whoami
With the command whoami you can check the user who is logged in. So you can use that in your script.
1)Create script
# vi test_root3.sh
if [ `whoami` = "root" ]
then
echo "You have logged on as root"
else
echo "You are not root user"
fi
2)Grant execute permission.
# chmod +x test_root3.sh
3)Test the script by running it.
# ./test_root3.sh
You have logged on as root
Tuesday, March 31, 2009
Copy files between Unix and Windows with rcp
There are many third party tools by which you can copy files between windows and unix machine. Some common tools are winscp, SSHSecureShellClient etc. Instead of using any third party tool, you can use original unix and windows built-in tool to do the task.
The RCP (Remote CoPy) is a standard UNIX tool and a Microsoft Windows 2000 tool that copies files/folder to and from computer running the RCP service.
Before you can use the RCP tool from a Windows-based computer you must do something in your UNIX computer.
you must turn on the RCP service and update the security files to allow the Windows-based computer to connect to your unix machine over this service.
The following steps will help you.
Step 01: Turn on RCP service on UNIX Host
Turn on the RCP service on unix machine by using inetd:
1. Log on as root.
2. Edit the file /etc/Inetd.conf.
3. Uncomment the lines that start with shell and that start with exec.
4. Save the file.
5. Use ps -ef |grep inetd and determine inetd service pid. Send the Host User Profile (HUP) signal to inetd by using kill or by using pkill.
6. Run inetd again.
To turn on the RCP service by using xinetd:
1. Log on as root.
2. Edit the file /etc/Xinetd.d/rsh. You may get another file based on your linux distrinution.
3. Change the line disable to no.
4. Save the file.
5. Use ps -ef |grep inetd and determine inetd service pid. Send the HUP signal to xinetd by using kill or by using pkill.
6. Run xinetd again.
Step 02: Set the security permissions
After turning on RCP services you must set the security permissions to allow the Windows host to connect to your computer.
1. Edit the file /etc/hosts.equiv. Based on your linux distribution this file may vary. You can get like /etc/hosts.allow.
2. In the file add a line that contains the name of your Windows host.
3. Add a second line that contains the name of your Windows host and the name of a user who can access the directory that you want to transfer. Separate the two elements with a tab character.
4. Save the file.
Step 03: Transfer the files or directory
From windows computer you can transfer files or folders using rcp using following syntax.
RCP [-a | -b] [-h] [-r] [host][.user:]source [host][.user:] path\destination
For example, to copy the file index.html from the path /home/oracle on the computer unixhost as the user oracle you must use from windows computer,
rcp unixhost.oracle:/home/oracle/index.html index.html
In order to copy whole directory you need to use -r(for recursive) with rcp command.
To copy test directory under /home/oracle on unix, from windows computer issue,
rcp -r unixhost.oracle:/home/oracle/test test
The RCP (Remote CoPy) is a standard UNIX tool and a Microsoft Windows 2000 tool that copies files/folder to and from computer running the RCP service.
Before you can use the RCP tool from a Windows-based computer you must do something in your UNIX computer.
you must turn on the RCP service and update the security files to allow the Windows-based computer to connect to your unix machine over this service.
The following steps will help you.
Step 01: Turn on RCP service on UNIX Host
Turn on the RCP service on unix machine by using inetd:
1. Log on as root.
2. Edit the file /etc/Inetd.conf.
3. Uncomment the lines that start with shell and that start with exec.
4. Save the file.
5. Use ps -ef |grep inetd and determine inetd service pid. Send the Host User Profile (HUP) signal to inetd by using kill or by using pkill.
6. Run inetd again.
To turn on the RCP service by using xinetd:
1. Log on as root.
2. Edit the file /etc/Xinetd.d/rsh. You may get another file based on your linux distrinution.
3. Change the line disable to no.
4. Save the file.
5. Use ps -ef |grep inetd and determine inetd service pid. Send the HUP signal to xinetd by using kill or by using pkill.
6. Run xinetd again.
Step 02: Set the security permissions
After turning on RCP services you must set the security permissions to allow the Windows host to connect to your computer.
1. Edit the file /etc/hosts.equiv. Based on your linux distribution this file may vary. You can get like /etc/hosts.allow.
2. In the file add a line that contains the name of your Windows host.
3. Add a second line that contains the name of your Windows host and the name of a user who can access the directory that you want to transfer. Separate the two elements with a tab character.
4. Save the file.
Step 03: Transfer the files or directory
From windows computer you can transfer files or folders using rcp using following syntax.
RCP [-a | -b] [-h] [-r] [host][.user:]source [host][.user:] path\destination
For example, to copy the file index.html from the path /home/oracle on the computer unixhost as the user oracle you must use from windows computer,
rcp unixhost.oracle:/home/oracle/index.html index.html
In order to copy whole directory you need to use -r(for recursive) with rcp command.
To copy test directory under /home/oracle on unix, from windows computer issue,
rcp -r unixhost.oracle:/home/oracle/test test
Monday, January 19, 2009
How to share and Access file on Solaris machine
In this example I will share a file from jupiter machine and then access it on neptune machine. Both machine uses Solaris platform.
1)On jupiter machine,
bash-3.00$ hostname
jupiter
Log on as a root user,
bash-3.00$ su
Password:
Change shell to bash
# bash
To make share persistence (after reboot is will also show) edit /etc/dfs/dfstab entry. Here I want to share directory /export/home/oracle and sharing option is read write.
# vi /etc/dfs/dfstab
share -F nfs -o rw /export/home/oracle
rw means read write permission You can also want to give ro (read only) instead of read write.
If you want it temporary you can do,
# share -F nfs -o rw /export/home/oracle
Restart your nfs server.
# /etc/init.d/nfs.server stop
# /etc/init.d/nfs.server start
Have a look at whether nfs server is running or not.
# ps -ef | grep nfs
daemon 317 1 0 Oct 10 ? 0:00 /usr/lib/nfs/lockd
daemon 311 1 0 Oct 10 ? 0:00 /usr/lib/nfs/statd
daemon 313 1 0 Oct 10 ? 0:03 /usr/lib/nfs/nfsmapid
daemon 291 1 0 Oct 10 ? 0:00 /usr/lib/nfs/nfs4cbd
root 12741 12424 0 03:20:34 pts/4 0:00 grep nfs
This must show statd and lockd running. In fact The statd and lockd must be running on server and
client.
Have a look at which file is shared and it's mode.
# share
- /export/home/oracle rw ""
2)On Saturn machine log on as a root user
oracle@neptune ~$ su -
Password:
Create a directory where you mount the network location.
root@neptune /# mkdir /export/home/oracle/remote
Mount the network drive
root@neptune /# mount -F nfs jupiter:/export/home/oracle /export/home/oracle/remote
Or, with more options issue,
# mount -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0 jupiter:/export/home/oracle /export/home/oracle/remote
See whether it is mounted.
root@neptune /# df -h
.
.
jupiter:/export/home/oracle
20G 7.6G 12G 39% /export/home/oracle/remote
Now do work is it /export/home/oracle/remote is your local disk location.
1)On jupiter machine,
bash-3.00$ hostname
jupiter
Log on as a root user,
bash-3.00$ su
Password:
Change shell to bash
# bash
To make share persistence (after reboot is will also show) edit /etc/dfs/dfstab entry. Here I want to share directory /export/home/oracle and sharing option is read write.
# vi /etc/dfs/dfstab
share -F nfs -o rw /export/home/oracle
rw means read write permission You can also want to give ro (read only) instead of read write.
If you want it temporary you can do,
# share -F nfs -o rw /export/home/oracle
Restart your nfs server.
# /etc/init.d/nfs.server stop
# /etc/init.d/nfs.server start
Have a look at whether nfs server is running or not.
# ps -ef | grep nfs
daemon 317 1 0 Oct 10 ? 0:00 /usr/lib/nfs/lockd
daemon 311 1 0 Oct 10 ? 0:00 /usr/lib/nfs/statd
daemon 313 1 0 Oct 10 ? 0:03 /usr/lib/nfs/nfsmapid
daemon 291 1 0 Oct 10 ? 0:00 /usr/lib/nfs/nfs4cbd
root 12741 12424 0 03:20:34 pts/4 0:00 grep nfs
This must show statd and lockd running. In fact The statd and lockd must be running on server and
client.
Have a look at which file is shared and it's mode.
# share
- /export/home/oracle rw ""
2)On Saturn machine log on as a root user
oracle@neptune ~$ su -
Password:
Create a directory where you mount the network location.
root@neptune /# mkdir /export/home/oracle/remote
Mount the network drive
root@neptune /# mount -F nfs jupiter:/export/home/oracle /export/home/oracle/remote
Or, with more options issue,
# mount -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0 jupiter:/export/home/oracle /export/home/oracle/remote
See whether it is mounted.
root@neptune /# df -h
.
.
jupiter:/export/home/oracle
20G 7.6G 12G 39% /export/home/oracle/remote
Now do work is it /export/home/oracle/remote is your local disk location.
How to share and Access file on Solaris machine
In this example I will share a file from jupiter machine and then access it on neptune machine. Both machine uses Solaris platform.
1)On jupiter machine,
bash-3.00$ hostname
jupiter
Log on as a root user,
bash-3.00$ su
Password:
Change shell to bash
# bash
To make share persistence (after reboot is will also show) edit /etc/dfs/dfstab entry. Here I want to share directory /export/home/oracle and sharing option is read write.
# vi /etc/dfs/dfstab
share -F nfs -o rw /export/home/oracle
rw means read write permission You can also want to give ro (read only) instead of read write.
If you want it temporary you can do,
# share -F nfs -o rw /export/home/oracle
Restart your nfs server.
# /etc/init.d/nfs.server stop
# /etc/init.d/nfs.server start
Have a look at whether nfs server is running or not.
# ps -ef | grep nfs
daemon 317 1 0 Oct 10 ? 0:00 /usr/lib/nfs/lockd
daemon 311 1 0 Oct 10 ? 0:00 /usr/lib/nfs/statd
daemon 313 1 0 Oct 10 ? 0:03 /usr/lib/nfs/nfsmapid
daemon 291 1 0 Oct 10 ? 0:00 /usr/lib/nfs/nfs4cbd
root 12741 12424 0 03:20:34 pts/4 0:00 grep nfs
This must show statd and lockd running. In fact The statd and lockd must be running on server and
client.
Have a look at which file is shared and it's mode.
# share
- /export/home/oracle rw ""
2)On Saturn machine log on as a root user
oracle@neptune ~$ su -
Password:
Create a directory where you mount the network location.
root@neptune /# mkdir /export/home/oracle/remote
Mount the network drive
root@neptune /# mount -F nfs jupiter:/export/home/oracle /export/home/oracle/remote
Or, with more options issue,
# mount -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0 jupiter:/export/home/oracle /export/home/oracle/remote
See whether it is mounted.
root@neptune /# df -h
.
.
jupiter:/export/home/oracle
20G 7.6G 12G 39% /export/home/oracle/remote
Now do work is it /export/home/oracle/remote is your local disk location.
1)On jupiter machine,
bash-3.00$ hostname
jupiter
Log on as a root user,
bash-3.00$ su
Password:
Change shell to bash
# bash
To make share persistence (after reboot is will also show) edit /etc/dfs/dfstab entry. Here I want to share directory /export/home/oracle and sharing option is read write.
# vi /etc/dfs/dfstab
share -F nfs -o rw /export/home/oracle
rw means read write permission You can also want to give ro (read only) instead of read write.
If you want it temporary you can do,
# share -F nfs -o rw /export/home/oracle
Restart your nfs server.
# /etc/init.d/nfs.server stop
# /etc/init.d/nfs.server start
Have a look at whether nfs server is running or not.
# ps -ef | grep nfs
daemon 317 1 0 Oct 10 ? 0:00 /usr/lib/nfs/lockd
daemon 311 1 0 Oct 10 ? 0:00 /usr/lib/nfs/statd
daemon 313 1 0 Oct 10 ? 0:03 /usr/lib/nfs/nfsmapid
daemon 291 1 0 Oct 10 ? 0:00 /usr/lib/nfs/nfs4cbd
root 12741 12424 0 03:20:34 pts/4 0:00 grep nfs
This must show statd and lockd running. In fact The statd and lockd must be running on server and
client.
Have a look at which file is shared and it's mode.
# share
- /export/home/oracle rw ""
2)On Saturn machine log on as a root user
oracle@neptune ~$ su -
Password:
Create a directory where you mount the network location.
root@neptune /# mkdir /export/home/oracle/remote
Mount the network drive
root@neptune /# mount -F nfs jupiter:/export/home/oracle /export/home/oracle/remote
Or, with more options issue,
# mount -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0 jupiter:/export/home/oracle /export/home/oracle/remote
See whether it is mounted.
root@neptune /# df -h
.
.
jupiter:/export/home/oracle
20G 7.6G 12G 39% /export/home/oracle/remote
Now do work is it /export/home/oracle/remote is your local disk location.
Friday, January 9, 2009
umask and permission in unix
Many one got confused with the setting of umask in unix or linux system. Whenever I was a newbie in this field I also got a bit confused with this settings. In a nutshell umask defines what will be the default permission of a file whenever a user create the file. You already are familiar with the unix permission of 754. The first digit 7(4 read +2 write+1 execute) is for permission for owner, the second digit 5 is for permission for the group and third digit 4 is for permission for others.
In brief,
Now lets a look at ls -l after creating a file without setting any umask.
-bash-3.00$ touch without_umask.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
After omitting first digit as it indicates whether file or folder we get
first 3 digit after - is 110 that is 6 for user oracle permission.
second pair of 3 digits are 100 that is 4 which is for all users who are under oinstall group.
third pair of 3 digits are 100 that is 4 which is for others.
Now start with setting umask of 022. With this setting, Files (and directories) normally created with mode 777 become mode 755. Files (and directories) created with mode 666 become mode 644).
In a word umask just deducted its value(here is 022) from 777 (or other mode that a file created) and then it changes permission to the file.
-bash-3.00$ umask 022
-bash-3.00$ touch with_umask1.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 022 set permission to with_umask1.txt file to 644.
-bash-3.00$ umask 002
-bash-3.00$ touch with_umask2.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 002 set permission to with_umask2.txt file to 664.
-bash-3.00$ umask 000
-bash-3.00$ touch with_umask3.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rw-rw-rw- 1 oracle oinstall 0 Aug 24 00:06 with_umask3.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 000 set permission to the file (666-000)=666.
We can chnage its settings later by chmod if we wish.
-bash-3.00$ chmod 777 with_umask3.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rwxrwxrwx 1 oracle oinstall 0 Aug 24 00:06 with_umask3.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
In brief,
User class: Owner Group Others
character representation: rwx r-x r--
binary representation: 111 101 100
octal representation: 7 5 4
Now lets a look at ls -l after creating a file without setting any umask.
-bash-3.00$ touch without_umask.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
After omitting first digit as it indicates whether file or folder we get
first 3 digit after - is 110 that is 6 for user oracle permission.
second pair of 3 digits are 100 that is 4 which is for all users who are under oinstall group.
third pair of 3 digits are 100 that is 4 which is for others.
Now start with setting umask of 022. With this setting, Files (and directories) normally created with mode 777 become mode 755. Files (and directories) created with mode 666 become mode 644).
In a word umask just deducted its value(here is 022) from 777 (or other mode that a file created) and then it changes permission to the file.
-bash-3.00$ umask 022
-bash-3.00$ touch with_umask1.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 022 set permission to with_umask1.txt file to 644.
-bash-3.00$ umask 002
-bash-3.00$ touch with_umask2.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 002 set permission to with_umask2.txt file to 664.
-bash-3.00$ umask 000
-bash-3.00$ touch with_umask3.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rw-rw-rw- 1 oracle oinstall 0 Aug 24 00:06 with_umask3.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 000 set permission to the file (666-000)=666.
We can chnage its settings later by chmod if we wish.
-bash-3.00$ chmod 777 with_umask3.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rwxrwxrwx 1 oracle oinstall 0 Aug 24 00:06 with_umask3.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
umask and permission in unix
Many one got confused with the setting of umask in unix or linux system. Whenever I was a newbie in this field I also got a bit confused with this settings. In a nutshell umask defines what will be the default permission of a file whenever a user create the file. You already are familiar with the unix permission of 754. The first digit 7(4 read +2 write+1 execute) is for permission for owner, the second digit 5 is for permission for the group and third digit 4 is for permission for others.
In brief,
Now lets a look at ls -l after creating a file without setting any umask.
-bash-3.00$ touch without_umask.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
After omitting first digit as it indicates whether file or folder we get
first 3 digit after - is 110 that is 6 for user oracle permission.
second pair of 3 digits are 100 that is 4 which is for all users who are under oinstall group.
third pair of 3 digits are 100 that is 4 which is for others.
Now start with setting umask of 022. With this setting, Files (and directories) normally created with mode 777 become mode 755. Files (and directories) created with mode 666 become mode 644).
In a word umask just deducted its value(here is 022) from 777 (or other mode that a file created) and then it changes permission to the file.
-bash-3.00$ umask 022
-bash-3.00$ touch with_umask1.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 022 set permission to with_umask1.txt file to 644.
-bash-3.00$ umask 002
-bash-3.00$ touch with_umask2.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 002 set permission to with_umask2.txt file to 664.
-bash-3.00$ umask 000
-bash-3.00$ touch with_umask3.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rw-rw-rw- 1 oracle oinstall 0 Aug 24 00:06 with_umask3.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 000 set permission to the file (666-000)=666.
We can chnage its settings later by chmod if we wish.
-bash-3.00$ chmod 777 with_umask3.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rwxrwxrwx 1 oracle oinstall 0 Aug 24 00:06 with_umask3.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
In brief,
User class: Owner Group Others
character representation: rwx r-x r--
binary representation: 111 101 100
octal representation: 7 5 4
Now lets a look at ls -l after creating a file without setting any umask.
-bash-3.00$ touch without_umask.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
After omitting first digit as it indicates whether file or folder we get
first 3 digit after - is 110 that is 6 for user oracle permission.
second pair of 3 digits are 100 that is 4 which is for all users who are under oinstall group.
third pair of 3 digits are 100 that is 4 which is for others.
Now start with setting umask of 022. With this setting, Files (and directories) normally created with mode 777 become mode 755. Files (and directories) created with mode 666 become mode 644).
In a word umask just deducted its value(here is 022) from 777 (or other mode that a file created) and then it changes permission to the file.
-bash-3.00$ umask 022
-bash-3.00$ touch with_umask1.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 022 set permission to with_umask1.txt file to 644.
-bash-3.00$ umask 002
-bash-3.00$ touch with_umask2.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 002 set permission to with_umask2.txt file to 664.
-bash-3.00$ umask 000
-bash-3.00$ touch with_umask3.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rw-rw-rw- 1 oracle oinstall 0 Aug 24 00:06 with_umask3.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Here we see umask of 000 set permission to the file (666-000)=666.
We can chnage its settings later by chmod if we wish.
-bash-3.00$ chmod 777 with_umask3.txt
-bash-3.00$ ls -l
total 0
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask1.txt
-rw-rw-r-- 1 oracle oinstall 0 Aug 24 00:06 with_umask2.txt
-rwxrwxrwx 1 oracle oinstall 0 Aug 24 00:06 with_umask3.txt
-rw-r--r-- 1 oracle oinstall 0 Aug 24 00:05 without_umask.txt
Thursday, January 8, 2009
How to change the hostname in Linux
There are several ways by which we can change the hostname in linux. The process may vary based on distribution of linux.
To see your system current host name use,
# hostname
# cat /bin/hostname
On debian system you can use,
# uname -n
To see the fully qualified domain name if you have use,
#hostname –fqd
Temporary Change hostname
To change the hostname temporary issue,
#hostname new_name which will change your current hostname to the new_name. You will most probably need to exit the current shell in order to see the change in your shell prompt. However changes in this way is not persistent because if the system reboot it will show the hostname values from a particular field.
Permanently change hostname of Debian Linux
To change the hostname of debian linux distribution edit the file /etc/hostname as debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
So, to change it in debian issue,
#vi /etc/hostname
and put a new entry there.
After changing to make it active run the script /etc/init.d/hostname.sh
# /etc/init.d/hostname.sh
Use sysctl to change the hostname both in RHL and debian
This process can be used both debian and red hat linux distribution. In this process use sysctl to change the variable kernel.hostname.
To read the current hostname issue,
#sysctl kernel.hostname
To change the current hostname to new_name issue,
#sysctl kernel.hostname=new_name
Change the hostname permanently in RHL Linux
This system is avilable for RHL distribution. Not apply for debian distribution. In this system change the network configuration file /etc/sysconfig/network in RHL.
Edit the /etc/sysconfig/network and change the hostname parameter to the new_name.
#vi /etc/sysconfig/network
HOSTNAME=new-host-name
Restart the network which relied on the hostname. You can perform reboot here.
# service network restart
Or,
#/etc/sysconfig/network-scripts/ifcfg-eth0
You may need to restart your console.
#init 3
#init 5
To see your system current host name use,
# hostname
# cat /bin/hostname
On debian system you can use,
# uname -n
To see the fully qualified domain name if you have use,
#hostname –fqd
Temporary Change hostname
To change the hostname temporary issue,
#hostname new_name which will change your current hostname to the new_name. You will most probably need to exit the current shell in order to see the change in your shell prompt. However changes in this way is not persistent because if the system reboot it will show the hostname values from a particular field.
Permanently change hostname of Debian Linux
To change the hostname of debian linux distribution edit the file /etc/hostname as debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
So, to change it in debian issue,
#vi /etc/hostname
and put a new entry there.
After changing to make it active run the script /etc/init.d/hostname.sh
# /etc/init.d/hostname.sh
Use sysctl to change the hostname both in RHL and debian
This process can be used both debian and red hat linux distribution. In this process use sysctl to change the variable kernel.hostname.
To read the current hostname issue,
#sysctl kernel.hostname
To change the current hostname to new_name issue,
#sysctl kernel.hostname=new_name
Change the hostname permanently in RHL Linux
This system is avilable for RHL distribution. Not apply for debian distribution. In this system change the network configuration file /etc/sysconfig/network in RHL.
Edit the /etc/sysconfig/network and change the hostname parameter to the new_name.
#vi /etc/sysconfig/network
HOSTNAME=new-host-name
Restart the network which relied on the hostname. You can perform reboot here.
# service network restart
Or,
#/etc/sysconfig/network-scripts/ifcfg-eth0
You may need to restart your console.
#init 3
#init 5
How to change the hostname in Linux
There are several ways by which we can change the hostname in linux. The process may vary based on distribution of linux.
To see your system current host name use,
# hostname
# cat /bin/hostname
On debian system you can use,
# uname -n
To see the fully qualified domain name if you have use,
#hostname –fqd
Temporary Change hostname
To change the hostname temporary issue,
#hostname new_name which will change your current hostname to the new_name. You will most probably need to exit the current shell in order to see the change in your shell prompt. However changes in this way is not persistent because if the system reboot it will show the hostname values from a particular field.
Permanently change hostname of Debian Linux
To change the hostname of debian linux distribution edit the file /etc/hostname as debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
So, to change it in debian issue,
#vi /etc/hostname
and put a new entry there.
After changing to make it active run the script /etc/init.d/hostname.sh
# /etc/init.d/hostname.sh
Use sysctl to change the hostname both in RHL and debian
This process can be used both debian and red hat linux distribution. In this process use sysctl to change the variable kernel.hostname.
To read the current hostname issue,
#sysctl kernel.hostname
To change the current hostname to new_name issue,
#sysctl kernel.hostname=new_name
Change the hostname permanently in RHL Linux
This system is avilable for RHL distribution. Not apply for debian distribution. In this system change the network configuration file /etc/sysconfig/network in RHL.
Edit the /etc/sysconfig/network and change the hostname parameter to the new_name.
#vi /etc/sysconfig/network
HOSTNAME=new-host-name
Restart the network which relied on the hostname. You can perform reboot here.
# service network restart
Or,
#/etc/sysconfig/network-scripts/ifcfg-eth0
You may need to restart your console.
#init 3
#init 5
To see your system current host name use,
# hostname
# cat /bin/hostname
On debian system you can use,
# uname -n
To see the fully qualified domain name if you have use,
#hostname –fqd
Temporary Change hostname
To change the hostname temporary issue,
#hostname new_name which will change your current hostname to the new_name. You will most probably need to exit the current shell in order to see the change in your shell prompt. However changes in this way is not persistent because if the system reboot it will show the hostname values from a particular field.
Permanently change hostname of Debian Linux
To change the hostname of debian linux distribution edit the file /etc/hostname as debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
So, to change it in debian issue,
#vi /etc/hostname
and put a new entry there.
After changing to make it active run the script /etc/init.d/hostname.sh
# /etc/init.d/hostname.sh
Use sysctl to change the hostname both in RHL and debian
This process can be used both debian and red hat linux distribution. In this process use sysctl to change the variable kernel.hostname.
To read the current hostname issue,
#sysctl kernel.hostname
To change the current hostname to new_name issue,
#sysctl kernel.hostname=new_name
Change the hostname permanently in RHL Linux
This system is avilable for RHL distribution. Not apply for debian distribution. In this system change the network configuration file /etc/sysconfig/network in RHL.
Edit the /etc/sysconfig/network and change the hostname parameter to the new_name.
#vi /etc/sysconfig/network
HOSTNAME=new-host-name
Restart the network which relied on the hostname. You can perform reboot here.
# service network restart
Or,
#/etc/sysconfig/network-scripts/ifcfg-eth0
You may need to restart your console.
#init 3
#init 5
How to change date and time on Linux using hand and NTP
I will write about two methods to change the time in Linux.
1. By hand. This setting may be be accurate as lots of clocks tend to drift over time.
2. Using NTP (Network Time Protocol). With this settings, you can get accurate time from a network time server.
1.By hand.
In order to see the current time and date settings issue,
[root@racnode-2 ~]# date
Thu Aug 14 17:49:04 BDT 2008
So current time is month 8 day 17, year 2008, time 17:49:04.
Now to change only time to 11:51.30 issue,
[root@racnode-2 ~]# date 08141151.30
Thu Aug 14 11:51:30 BDT 2008
Now issue date,
[root@racnode-2 ~]# date
Thu Aug 14 11:51:32 BDT 2008
Note that setting date in this way will not cause the date to remain after a reboot. The date command sets the Linux system clock which is separate from the hardware clock.
We can check linux hardware clock by,
[root@racnode-2 ~]# hwclock
Thu 14 Aug 2008 05:57:01 PM BDT -0.788181 seconds
To make date setting persistent update the hardware clock with the date from the Linux system clock.
[root@racnode-2 ~]# /sbin/hwclock --systohc
If you are using universal time then use,
hwclock --utc --systohc
An alternative way is if you want to set the hardware(BIOS) clock so the system will keep the time when it reboots using,
clock -w
or
setclock
after changing date and time by date command.
To set date and time we can also use,
# date -s "2 OCT 2008 8:00:00"
If you wanted to change the year as well, for example to change year to 2007 of 30th April time 11:16pm you could type
#date 043023162007
To change only the time to 10:10 am you also can use,
#date -s 10:10
2.Using NTP (Network Time Protocol).
This is simple process. Just adding the time server to /etc/ntp.conf and to /etc/ntp/step-tickers Here I use time server as 192.168.1.91.
#vi /etc/ntp.conf
server 192.168.1.91
#vi /etc/ntp/step-tickers
192.168.1.91
Then of course make sure that ntp will start at boot time by,
chkconfig --level 2345 ntpd on
chkconfig --list ntpd
And let's start the service now by,
service ntpd start
It will display output as
ntpd: Synchronizing with time server: [ OK ]
Starting ntpd: [ OK ]
1. By hand. This setting may be be accurate as lots of clocks tend to drift over time.
2. Using NTP (Network Time Protocol). With this settings, you can get accurate time from a network time server.
1.By hand.
In order to see the current time and date settings issue,
[root@racnode-2 ~]# date
Thu Aug 14 17:49:04 BDT 2008
So current time is month 8 day 17, year 2008, time 17:49:04.
Now to change only time to 11:51.30 issue,
[root@racnode-2 ~]# date 08141151.30
Thu Aug 14 11:51:30 BDT 2008
Now issue date,
[root@racnode-2 ~]# date
Thu Aug 14 11:51:32 BDT 2008
Note that setting date in this way will not cause the date to remain after a reboot. The date command sets the Linux system clock which is separate from the hardware clock.
We can check linux hardware clock by,
[root@racnode-2 ~]# hwclock
Thu 14 Aug 2008 05:57:01 PM BDT -0.788181 seconds
To make date setting persistent update the hardware clock with the date from the Linux system clock.
[root@racnode-2 ~]# /sbin/hwclock --systohc
If you are using universal time then use,
hwclock --utc --systohc
An alternative way is if you want to set the hardware(BIOS) clock so the system will keep the time when it reboots using,
clock -w
or
setclock
after changing date and time by date command.
To set date and time we can also use,
# date -s "2 OCT 2008 8:00:00"
If you wanted to change the year as well, for example to change year to 2007 of 30th April time 11:16pm you could type
#date 043023162007
To change only the time to 10:10 am you also can use,
#date -s 10:10
2.Using NTP (Network Time Protocol).
This is simple process. Just adding the time server to /etc/ntp.conf and to /etc/ntp/step-tickers Here I use time server as 192.168.1.91.
#vi /etc/ntp.conf
server 192.168.1.91
#vi /etc/ntp/step-tickers
192.168.1.91
Then of course make sure that ntp will start at boot time by,
chkconfig --level 2345 ntpd on
chkconfig --list ntpd
And let's start the service now by,
service ntpd start
It will display output as
ntpd: Synchronizing with time server: [ OK ]
Starting ntpd: [ OK ]
How to change date and time on Linux using hand and NTP
I will write about two methods to change the time in Linux.
1. By hand. This setting may be be accurate as lots of clocks tend to drift over time.
2. Using NTP (Network Time Protocol). With this settings, you can get accurate time from a network time server.
1.By hand.
In order to see the current time and date settings issue,
[root@racnode-2 ~]# date
Thu Aug 14 17:49:04 BDT 2008
So current time is month 8 day 17, year 2008, time 17:49:04.
Now to change only time to 11:51.30 issue,
[root@racnode-2 ~]# date 08141151.30
Thu Aug 14 11:51:30 BDT 2008
Now issue date,
[root@racnode-2 ~]# date
Thu Aug 14 11:51:32 BDT 2008
Note that setting date in this way will not cause the date to remain after a reboot. The date command sets the Linux system clock which is separate from the hardware clock.
We can check linux hardware clock by,
[root@racnode-2 ~]# hwclock
Thu 14 Aug 2008 05:57:01 PM BDT -0.788181 seconds
To make date setting persistent update the hardware clock with the date from the Linux system clock.
[root@racnode-2 ~]# /sbin/hwclock --systohc
If you are using universal time then use,
hwclock --utc --systohc
An alternative way is if you want to set the hardware(BIOS) clock so the system will keep the time when it reboots using,
clock -w
or
setclock
after changing date and time by date command.
To set date and time we can also use,
# date -s "2 OCT 2008 8:00:00"
If you wanted to change the year as well, for example to change year to 2007 of 30th April time 11:16pm you could type
#date 043023162007
To change only the time to 10:10 am you also can use,
#date -s 10:10
2.Using NTP (Network Time Protocol).
This is simple process. Just adding the time server to /etc/ntp.conf and to /etc/ntp/step-tickers Here I use time server as 192.168.1.91.
#vi /etc/ntp.conf
server 192.168.1.91
#vi /etc/ntp/step-tickers
192.168.1.91
Then of course make sure that ntp will start at boot time by,
chkconfig --level 2345 ntpd on
chkconfig --list ntpd
And let's start the service now by,
service ntpd start
It will display output as
ntpd: Synchronizing with time server: [ OK ]
Starting ntpd: [ OK ]
1. By hand. This setting may be be accurate as lots of clocks tend to drift over time.
2. Using NTP (Network Time Protocol). With this settings, you can get accurate time from a network time server.
1.By hand.
In order to see the current time and date settings issue,
[root@racnode-2 ~]# date
Thu Aug 14 17:49:04 BDT 2008
So current time is month 8 day 17, year 2008, time 17:49:04.
Now to change only time to 11:51.30 issue,
[root@racnode-2 ~]# date 08141151.30
Thu Aug 14 11:51:30 BDT 2008
Now issue date,
[root@racnode-2 ~]# date
Thu Aug 14 11:51:32 BDT 2008
Note that setting date in this way will not cause the date to remain after a reboot. The date command sets the Linux system clock which is separate from the hardware clock.
We can check linux hardware clock by,
[root@racnode-2 ~]# hwclock
Thu 14 Aug 2008 05:57:01 PM BDT -0.788181 seconds
To make date setting persistent update the hardware clock with the date from the Linux system clock.
[root@racnode-2 ~]# /sbin/hwclock --systohc
If you are using universal time then use,
hwclock --utc --systohc
An alternative way is if you want to set the hardware(BIOS) clock so the system will keep the time when it reboots using,
clock -w
or
setclock
after changing date and time by date command.
To set date and time we can also use,
# date -s "2 OCT 2008 8:00:00"
If you wanted to change the year as well, for example to change year to 2007 of 30th April time 11:16pm you could type
#date 043023162007
To change only the time to 10:10 am you also can use,
#date -s 10:10
2.Using NTP (Network Time Protocol).
This is simple process. Just adding the time server to /etc/ntp.conf and to /etc/ntp/step-tickers Here I use time server as 192.168.1.91.
#vi /etc/ntp.conf
server 192.168.1.91
#vi /etc/ntp/step-tickers
192.168.1.91
Then of course make sure that ntp will start at boot time by,
chkconfig --level 2345 ntpd on
chkconfig --list ntpd
And let's start the service now by,
service ntpd start
It will display output as
ntpd: Synchronizing with time server: [ OK ]
Starting ntpd: [ OK ]
Thursday, January 1, 2009
TNSPING
Oracle has a utility called tnsping that can be used to determine if a particular Oracle service (such as the database itself) can be reached from a particular client or server, and also how long it took.
Here is an example of how to test your connection to a service named service_name (in tnsnames.ora) 5 times.
TNS Ping Utility for 32-bit Windows: Version 9.2.0.5.0 - Production on 18-APR-20
08 09:42:15
Copyright (c) 1997 Oracle Corporation. All rights reserved.
Used parameter files:
C:\ORACLE9\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 10.72.1.1) (PORT = 1234)) (CONNECT_DATA = (SID = service_name) (GLOBAL_NAME = service_name.domain.com)))
OK (20 msec)
OK (0 msec)
OK (0 msec)
OK (10 msec)
OK (0 msec)
(Yes, I'm still using Oracle 9, stop laughing)
What kind of errors can come back? You might get TNS-03505 if the service name is invalid, or TNS-12541 if that name can't be resolved to a service with a functioning listener.
You may also be interested in the TRCROUTE utility which will give you information about the actual route the test packet took.
Here is an example of how to test your connection to a service named service_name (in tnsnames.ora) 5 times.
TNS Ping Utility for 32-bit Windows: Version 9.2.0.5.0 - Production on 18-APR-20
08 09:42:15
Copyright (c) 1997 Oracle Corporation. All rights reserved.
Used parameter files:
C:\ORACLE9\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 10.72.1.1) (PORT = 1234)) (CONNECT_DATA = (SID = service_name) (GLOBAL_NAME = service_name.domain.com)))
OK (20 msec)
OK (0 msec)
OK (0 msec)
OK (10 msec)
OK (0 msec)
(Yes, I'm still using Oracle 9, stop laughing)
What kind of errors can come back? You might get TNS-03505 if the service name is invalid, or TNS-12541 if that name can't be resolved to a service with a functioning listener.
You may also be interested in the TRCROUTE utility which will give you information about the actual route the test packet took.
TNSPING
Oracle has a utility called tnsping that can be used to determine if a particular Oracle service (such as the database itself) can be reached from a particular client or server, and also how long it took.
Here is an example of how to test your connection to a service named service_name (in tnsnames.ora) 5 times.
TNS Ping Utility for 32-bit Windows: Version 9.2.0.5.0 - Production on 18-APR-20
08 09:42:15
Copyright (c) 1997 Oracle Corporation. All rights reserved.
Used parameter files:
C:\ORACLE9\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 10.72.1.1) (PORT = 1234)) (CONNECT_DATA = (SID = service_name) (GLOBAL_NAME = service_name.domain.com)))
OK (20 msec)
OK (0 msec)
OK (0 msec)
OK (10 msec)
OK (0 msec)
(Yes, I'm still using Oracle 9, stop laughing)
What kind of errors can come back? You might get TNS-03505 if the service name is invalid, or TNS-12541 if that name can't be resolved to a service with a functioning listener.
You may also be interested in the TRCROUTE utility which will give you information about the actual route the test packet took.
Here is an example of how to test your connection to a service named service_name (in tnsnames.ora) 5 times.
TNS Ping Utility for 32-bit Windows: Version 9.2.0.5.0 - Production on 18-APR-20
08 09:42:15
Copyright (c) 1997 Oracle Corporation. All rights reserved.
Used parameter files:
C:\ORACLE9\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 10.72.1.1) (PORT = 1234)) (CONNECT_DATA = (SID = service_name) (GLOBAL_NAME = service_name.domain.com)))
OK (20 msec)
OK (0 msec)
OK (0 msec)
OK (10 msec)
OK (0 msec)
(Yes, I'm still using Oracle 9, stop laughing)
What kind of errors can come back? You might get TNS-03505 if the service name is invalid, or TNS-12541 if that name can't be resolved to a service with a functioning listener.
You may also be interested in the TRCROUTE utility which will give you information about the actual route the test packet took.
Subscribe to:
Posts (Atom)