Friday, April 24, 2026

Exactely Y or N in terminal C++ CLI

 To get exactly Y/N for yes or no, and not other than those :-
-------------------------------------------------------------

here you need shared library for "clrscr-getch.h" and "str-manip.h"

first for "gotoxy(......) & other functions and second for "trimstring(......)"

I have already posted for both libraries.

 This gets only "Y" or "N", and not mare than that. Even does not display other than characters "Y" or "N". By default "Y" option is dispalyed. If user hit direct "Enter key", before yes or no, default yes ("Y") is returened.
 Here most of the validations are handled.

#include <iostream>

#include <clrscr-getch/clrscr-getch.h>
#include <str-manip/str-manip.h>

using namespace std;

bool getYesNo(const int xcoord, const int ycoord, char *yn);

int main()
{
    bool tf;

    char yn;

    CClrscrGetch *get = new CClrscrGetch;

    get->clrscr();

    cout << "Enter Y/N : ";

    tf = getYesNo(13, 1, &yn);

    cout << endl;

    if(tf == true)
    {
        cout << "Y/N : " << yn;
    }
    else
    {
        cout << "Invalid ";
    }

    cout << endl;

    delete get;

    return 0;
}

bool getYesNo(const int xcoord, const int ycoord, char *yn)
{
    string strin;

    char key = 'Y';

    bool tf = false;

    CClrscrGetch *get = new CClrscrGetch;

    strin.clear();

    int i = 0;

    while(1)
    {
        get->gotoxy(xcoord, ycoord);

        if(key == 'Y' || key == 'y' || key == 'N' || key == 'n')
        {
            key = char(toupper(key));

            cout << key;
            strin = key;
        }

        get->gotoxy(xcoord + 2, ycoord);

        key = get->getch();

        strin += key;

        tf = CString::trimString(&strin);

        if(tf == false)
        {
            continue;
        }

        if(tf == true && strin.length() > 1 && int(key) != 10)
        {
            strin.pop_back();

            continue;
        }

        if(int(key) == 10) // Enter key = 10
        {
            *yn = strin.at(0);

            delete get;
             return true;
        }
        else
        {
            continue;
        }
    }
}

/* O/P :-
Enter Y/N : Y                                                                                                      

Y/N :Y

 [rahul@kaljayi Release]$ 

Enter Y/N : N

 Y/N :N
[rahul@kaljayi Release]$ 

*/
















Tuesday, April 21, 2026

Adding new harddisk into VM Linux

 adding new hard disk to linux VM :-
-----------------------------------

1. Add new HDD via VM settings.

2. power on VM.

3. run following command as root user.

# echo "- - -" | sudo tee /sys/class/scsi_host/host*/scan >/dev/null

# lsblk <-|(i.e. press Enter )

this will show you newlly added HDDs. But right now you can not use directely.
First you have to create filesystem in it and make filesystem of "xfs". Then only you can get it in your OS. So do these :-

for example these are mine output :-

------------------------------------------------

[root@ora12cserver oracle]# echo "- - -" | sudo tee /sys/class/scsi_host/host*/scan >/dev/null
[root@ora12cserver oracle]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  100G  0 disk 
├─sda1   8:1    0 1000M  0 part /boot
├─sda2   8:2    0   20G  0 part /oraGridDisk1
├─sda3   8:3    0   20G  0 part /oraGridDisk2
├─sda4   8:4    0    1K  0 part 
├─sda5   8:5    0   16G  0 part [SWAP]
├─sda6   8:6    0   15G  0 part /oraGridDisk3
└─sda7   8:7    0   28G  0 part /
sdb      8:16   0   20G  0 disk 
sdc      8:32   0   20G  0 disk 
sr0     11:0    1  4.1G  0 rom  /run/media/oracle/OL-7.5 Server.x86_64

------------------------------------------------

Now to create new partition fire these commands :-

# fdisk /dev/sdb

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


[root@ora12cserver oracle]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  100G  0 disk 
├─sda1   8:1    0 1000M  0 part /boot
├─sda2   8:2    0   20G  0 part /oraGridDisk1
├─sda3   8:3    0   20G  0 part /oraGridDisk2
├─sda4   8:4    0    1K  0 part 
├─sda5   8:5    0   16G  0 part [SWAP]
├─sda6   8:6    0   15G  0 part /oraGridDisk3
└─sda7   8:7    0   28G  0 part /
sdb      8:16   0   20G  0 disk 
└─sdb1   8:17   0   20G  0 part 
sdc      8:32   0   20G  0 disk 
sr0     11:0    1  4.1G  0 rom  /run/media/oracle/OL-7.5 Server.x86_64

then :-

[root@ora12cserver oracle]# mkfs.xfs /dev/sdb1
now 

[root@ora12cserver oracle]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x0d073c9d.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@ora12cserver oracle]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  100G  0 disk 
├─sda1   8:1    0 1000M  0 part /boot
├─sda2   8:2    0   20G  0 part /oraGridDisk1
├─sda3   8:3    0   20G  0 part /oraGridDisk2
├─sda4   8:4    0    1K  0 part 
├─sda5   8:5    0   16G  0 part [SWAP]
├─sda6   8:6    0   15G  0 part /oraGridDisk3
└─sda7   8:7    0   28G  0 part /
sdb      8:16   0   20G  0 disk 
└─sdb1   8:17   0   20G  0 part 
sdc      8:32   0   20G  0 disk 
└─sdc1   8:33   0   20G  0 part 
sr0     11:0    1  4.1G  0 rom  /run/media/oracle/OL-7.5 Server.x86_64
[root@ora12cserver oracle]# mount /dev/sdb1 /mnt/sdb1
[root@ora12cserver oracle]# mkfs.xfs /dev/sdc1
meta-data=/dev/sdc1              isize=256    agcount=4, agsize=1310656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5242624, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@ora12cserver oracle]# mount /dev/sdc1 /mnt/sdc1
[root@ora12cserver oracle]#