Monday, February 5, 2024

Unix/Linux get started Lesson 01

 

Unix/Linux get started

What is Unix ?

The Unix operating system is a set of programs that act as a link between the computer and the user.

The computer programs that allocate the system resources and coordinate all the details of the computer's internals is called the operating system or the kernel.

Unix Architecture



·         Kernel − The kernel is the heart of the operating system. It interacts with the hardware and most of the tasks like memory management, task scheduling and file management.

·         Shell − The shell is the utility that processes your requests. When you type in a command at your terminal, the shell interprets the command and calls the program that you want. The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are the most famous shells which are available with most of the Unix variants.

·         Commands and Utilities − There are various commands and utilities which you can make use of in your day to day activities. cpmvcat and grep, etc. are few examples of commands and utilities. There are over 250 standard commands plus numerous others provided through 3rd party software. All the commands come along with various options.

·         Files and Directories − All the data of Unix is organized into files. All files are then organized into directories. These directories are further organized into a tree-like structure called the filesystem.

 

Lets see how we log in to Linux:

 

login : root

root's password:
Last login: Mon Feb  5 09:58:32 2024 from 192.168.15.60



 

 

Change Password

#passwd
Changing password for root
(current) Unix password:******
New UNIX password:*******
 
 

Listing Directories and Files

 

All data in Unix is organized into files. All files are organized into directories. These directories are organized into a tree-like structure called the filesystem.

You can use the ls command to list out all the files or directories available in a directory. Following is the example of using ls command with -l option.



Who Are You?


 


Who is Logged in?

 


 

System Shutdown

The most consistent way to shut down a Unix system properly via the command line is to use one of the following commands −

1

halt

Brings the system down immediately

2

init 0

Powers off the system using predefined scripts to synchronize and clean up the system prior to shutting down

3

init 6

Reboots the system by shutting it down completely and then restarting it

4

poweroff

Shuts down the system by powering off

5

reboot

Reboots the system

6

shutdown

Shuts down the system

 
 
 

 

 

 

 

Wednesday, December 27, 2023

Automate RMAN Backup using Shell Script

 


In a real environment, off course you will not manually trigger all the Oracle database backups. You need an automated mechanism to trigger RMAN backups. So in this topic we will learn how to set RMAN backup automation using shell scripts.







Schedule Backup Under Crontab



Give execute permissions on the shell script

chmod 775 /u01/backup/BKP_DEV_05172023/full_backup.sh

Now you can go ahead and schedule the backup under the crontab. For example, we are

scheduling backup to trigger every Tuesday and Friday at midnight

 

crontab -e

 

0 0 * * FRI,TUE /u01/backup/ BKP_DEV_05172023/full_backup.sh



Crontab tool

Her is the crontab tool I use (https://crontab.guru/ )that I use to accurately define when crontab will execute next.


Cron Job Schedule Syntax

A basic crontab entry looks something like this:

*    *    *    *    *   /home/user/bin/somecommand.sh
|    |    |    |    |            |
|    |    |    |    |    Command or Script to execute
|    |    |    |    |
|    |    |    | Day of week(0-6 | Sun-Sat)
|    |    |    |
|    |    |  Month(1-12)
|    |    |
|    |  Day of Month(1-31)
|    |
|   Hour(0-23)
|
Min(0-59)

An asterisk (*) matches all values, so if you take a look at the example above, it specifies that /home/user/bin/somecommand.sh should be run at minutes 0-59 and hours 0-23 on days of the month 1-31 for months 1-12 on days of week 0-6 — or in other words "every minute".

Cron entries can also be configured to run at more complex times. If you want to run four times a day between Monday and Friday, you can use the step operator ( / ) and the range operator ( - ).



 

12 essential Linux commands for beginners

 

I recommend these commands to anyone who is getting started with Linux.

1. Print working directory (pwd)

The pwd command prints your working directory. In other words, it outputs the path of the directory you are currently working in. There are two options: --logical to display your location with any symlinks and --physical to display your location after resolving any symlinks.

2. Make directory (mkdir)

Making directories is easy with the mkdir command. The following command creates a directory called test unless test already exists:

$ mkdir test

You can make directories within directories:

$ mkdir -p test/one/two

If directories test and one already exist, only directory two is created. If none of them exist, then three nested directories are created.

3. List (ls)

Coming from MS-DOS, I was used to listing files with the dir command. I don't recall working on Linux at the time, although today, dir is in the GNU Core Utilities package. Most people use the ls command to display the files, along with all their properties, are in a directory. The ls command has many options, including -l to view a long listing of files, displaying the file owner and permissions.

4. Change directory (cd)

It is often necessary to change directories. That's the cd command's function. For instance, this test takes you from your home directory into the Downloads directory:

$ cd Downloads

You can quickly change to your home directory with cd ~ or just cd on most systems. You can use cd .. to move up a level.

5. Remove a file (rm)

Removing files is inherently dangerous. Traditionally, the Linux terminal has no Trash or Bin like the desktop does, so many terminal users have the bad habit of permanently removing data they believe they no longer need. There's no "un-remove" command, though, so this habit can be problematic should you accidentally delete a directory containing important data.

A Linux system provides rm and shred for data removal. To delete file read.txt, type the following:

$ rm read.txt

However, it's much safer to install a trash command, such as trashy or trash-cli. Then you can send files to a staging area before deleting them forever:

$ trash read.txt

6. Copy a file (cp)

Copy files with the cp command. The syntax is copy from-here to-there. Here's an test:

$ cp test1.txt newtest1.txt

You can copy entire directories, too:

$ cp -r dir1 newdirectory

7. Move and rename a file (mv)

Renaming and moving a file is functionally the same process. When you move a file, you take a file from one directory and put it into a new one. When renaming a file, you take a file from one directory and put it back into the same directory or a different directory, but with a new name. Either way, you use the mv command:

$ mv test1.txt file_test1.txt

8. Create an empty file (touch)

Easily create an empty file with the touch command:

$ touch one.txt

 

$ touch two.txt

 

$ touch three.md

9. Change permissions (chmod)

Change the permissions of a file with the chmod command. One of the most common uses of chmod is making a file executable:

$ chmod +x myfile

This test is how you give a file permission to be executed as a command. This is particularly handy for scripts. Try this simple exercise:

$ echo 'echo Hello $USER' > hello.sh

 

$ chmod +x hello.sh

 

$ ./hello.sh

Hello, TOM

10. Escalate privileges (sudo)

While administering your system, it may be necessary to act as the super user (also called root). This is where the sudo (or super user do) command comes in. Assuming you're trying to do something that your computer alerts you that only an administrator (or root) user can do, just preface it with the command sudo:

$ touch /etc/os-release && echo "Success"

touch: cannot touch '/etc/os-release': Permission denied

 

$ sudo touch /etc/os-release && echo "Success"

Success

11. Shut down (poweroff)

The poweroff command does exactly what it sounds like: it powers your computer down. It requires sudo to succeed.

There are actually many ways to shut down your computer and some variations on the process. For instance, the shutdown command allows you to power down your computer after an arbitrary amount of time, such as 60 seconds:

$ sudo shutdown -h 60

Or immediately:

$ sudo shutdown -h now

You can also restart your computer with sudo shutdown -r now or just reboot.

12. Read the manual (man)

The man command could be the most important command of all. It gets you to the documentation for each of the commands on your Linux system. For instance, to read more about mkdir:

$ man mkdir

 

Logical Standby in Oracle Data Guard Overview

  In Oracle Data Guard , a Logical Standby Database is a standby database that: Receives redo data from the Primary database Convert...