Setup Unix Profile

cat > ~/.bash_aliases
.profile _orig
.bashrc _orig

In the File ” .bash_aliases ”  add following.

 alias c=clear
 alias e='exit'
 alias m='less -i'
 alias ll='ls -alrtF'
 alias dird='ls -alrt | grep ^d'


 alias shut='sudo shutdown -P now'

After this does not go into .bash_aliases file.

This is just for reference to update/install Linux OS.

dd bs=4M status=progress if=ubuntu-16.04-desktop-amd64.iso of=/dev/sdc1

main@main-desktop:~/Downloads$ pwd
/home/main/Downloads
main@main-desktop:~/Downloads$ ll ubuntu-16.04.1-desktop-amd64.iso 
-rw-rw-r-- 1 main main 1513308160 Aug 17 16:48 ubuntu-16.04.1-desktop-amd64.iso
main@main-desktop:~/Downloads$
cd ~main/Downloads
sudo dd bs=4M status=progress if=ubuntu-16.04-desktop-amd64.iso of=/dev/sdb 
sudo apt-get install unetbootin
sudo unetbootin
set -o vi

# This is I think original PS1
## PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'

# This PS1 prints HOSTNAME in window /h and VERSION /v
PS1='\[\e]0;\u@\v: \h: cmd# \#: /pts/\l : Time \t: \w\a\]${debian_chroot:+($debian_chroot)}\u@\$:\#:\w\$ '

# This PS1 prints USER /u \$ and then VERSION \v
PS1='\[\e]0;\u@\$: \v: cmd# \#: /pts/\l : Time \t: \w\a\]${debian_chroot:+($debian_chroot)}\u@\$:\#:\w\$ '

alias c=clear
alias d=date
alias e=exit
alias m='less -i'

alias ll='\ls -alrt'
alias llA='\ls -Alrt'

alias dird='\ls -alrt| grep ^d'

alias vmplayer='cd /home//Hadoop/cloudera-quickstart-vm-5.4.2-0-vmware; vmplayer cloudera-quickstart-vm-5.4.2-0-vmware.vmx; cd -; '







# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
 PATH="$HOME/bin:$PATH"
fi


. ${HOME}/bin/.chk_bin ${HOME}/GURU/script

export LPDEST=''
echo -e "Print ----- lpr -P  /usr/share/cups/data/testprint -----\n\n LPDEST ----- lpstat -----\n\n\n"

. .Mongo; echo -e "WRA Mongo WRA\t\t:hll2320d:\n\n\n\n\n"

script with admin privileges

File delete_media.sh

# You need to give password for USER <USERNAME>

echo "Please Enter the password for USER `tput smso`<USERNAME>`tput rmso`"

su - <USERNAME> -c "sh bin/del_media_dir.sh"

 

File dell_media_dir.sh

#!/bin/sh +xv

# set +xv
echo "\n\n\nThis is the Program to remove EXTERNAL HARD DISK DRIVES(e.g. USB, HDD, etc.) :\nProgram is : [`tput smso`{ $0 }`tput rmso`] :\n\n"

# echo $* 
# echo $1

cd /media
echo "Current Directory is : [`tput smso`{ `pwd` }`tput rmso`] :"
# pwd

echo -n "\nExisting files in above Directory are : [`tput smso`{ "
echo -n `ls`
echo " }`tput rmso`] :\n\n\n"


for i in `ls`
do
echo " `tput smso`{ ${i} }`tput rmso`\n\n"


echo "Do you want to delete `tput smso`${i}`tput rmso`"
read ans

# echo ${ans}
ans=`echo ${ans} | tr [:upper:] [:lower:]`
# echo "ANS ${ans} after proper"
echo "ANS :`tput smso` ${ans}`tput rmso`"

# set -xv

if [ "${ans}" = "y" ]
then
    echo "\nYes:\nI am going to delete Directory : \t `tput smso`{ /media/${i} }`tput rmso`\n\n\n"

##### Add following lines in /etc/sudoers so "sudo /bin/rmdir functions as intended"
##### <USERNAME> ALL=(ALL) NOPASSWD: /bin/rmdir
    sudo /bin/rmdir /media/${i}
fi

sleep 3
done


echo "Please press Enter"
read Enter
sleep 11


cd -
# pwd

 

setup virtualenv python

Installation

https://virtualenv.pypa.io/en/stable/installation/
$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-X.X.tar.gz
$ tar xvfz virtualenv-X.X.tar.gz ( virtualenv-15.1.0.tar.gz )
$ cd virtualenv-X.X
$ python virtualenv.py myVE

Setup Virtual Environment

$ python virtualenv.py Py_2.7.13

Activate Virtual Environment ( Activate Script )

$ source bin/activate

Deactivate Virtual Environment

$ deactivate

Removing an Environment

$ deactivate
$ rm -r /path/to/ENV

Running the Tests

$ python setup.py test

Install Scientific Packages

$ pip install nose pandas numpy scipy pytest

Result of Installing Packages

$ pip install nose pandas numpy scipy pytest
Collecting nose
  Downloading nose-1.3.7-py2-none-any.whl (154kB)
    100% |████████████████████████████████| 163kB 162kB/s 
Collecting pandas
  Downloading pandas-0.20.1-cp27-cp27mu-manylinux1_x86_64.whl (22.3MB)
    100% |████████████████████████████████| 22.3MB 29kB/s 
Collecting numpy
  Downloading numpy-1.12.1-cp27-cp27mu-manylinux1_x86_64.whl (16.5MB)
    100% |████████████████████████████████| 16.5MB 42kB/s 
Collecting scipy
  Downloading scipy-0.19.0-cp27-cp27mu-manylinux1_x86_64.whl (45.0MB)
    100% |████████████████████████████████| 45.0MB 17kB/s 
Collecting pytest
  Downloading pytest-3.1.0-py2.py3-none-any.whl (178kB)
    100% |████████████████████████████████| 184kB 136kB/s 
Collecting pytz>=2011k (from pandas)
  Downloading pytz-2017.2-py2.py3-none-any.whl (484kB)
    100% |████████████████████████████████| 491kB 276kB/s 
Collecting python-dateutil (from pandas)
  Downloading python_dateutil-2.6.0-py2.py3-none-any.whl (194kB)
    100% |████████████████████████████████| 194kB 198kB/s 
Requirement already satisfied: setuptools in ./lib/python2.7/site-packages (from pytest)
Collecting py>=1.4.29 (from pytest)
  Downloading py-1.4.33-py2.py3-none-any.whl (83kB)
    100% |████████████████████████████████| 92kB 309kB/s 
Requirement already satisfied: six>=1.5 in ./lib/python2.7/site-packages (from python-dateutil->pandas)
Requirement already satisfied: appdirs>=1.4.0 in ./lib/python2.7/site-packages (from setuptools->pytest)
Requirement already satisfied: packaging>=16.8 in ./lib/python2.7/site-packages (from setuptools->pytest)
Requirement already satisfied: pyparsing in ./lib/python2.7/site-packages (from packaging>=16.8->setuptools->pytest)
Installing collected packages: nose, pytz, python-dateutil, numpy, pandas, scipy, py, pytest
Successfully installed nose-1.3.7 numpy-1.12.1 pandas-0.20.1 py-1.4.33 pytest-3.1.0 python-dateutil-2.6.0 pytz-2017.2 scipy-0.19.0
$

Result of pip freeze;  alert

$ pip freeze;  alert
appdirs==1.4.3
nose==1.3.7
numpy==1.12.1
packaging==16.8
pandas==0.20.1
py==1.4.33
pyparsing==2.2.0
pytest==3.1.0
python-dateutil==2.6.0
pytz==2017.2
scipy==0.19.0
six==1.10.0

ubuntu xchange /dev/sda with /dev/sdb

I want to change /dev/sda to /dev/sdb and /dev/sdb to /dev/sda .

I used following steps :

sudo hdparm -I /dev/sda | grep -A 2 Model

 

If anyone’s interested, I created a file called 10-local.rules in /etc/udev/rules.d:

# If the kernel matches a device as sda, change it to sdb.
 KERNEL=="sda", NAME="sdb"
# Vice versa.
 KERNEL=="sdb", NAME="sda"

 

#Add ID_SERIAL and other variables into the environment
ACTION=="add", KERNEL=="/dev/[sh]d[a-z]", IMPORT{program}="ata_id --export $tempnode"
#Add symlink to hard drive
KERNEL=="/dev/[sh]d[a-z]", ENV{ID_SERIAL}=="WD-WCANU1937055", SYMLINK+="timsdisks/500gb_a"

 

Reference :

http://stackoverflow.com/questions/18422500/how-do-you-swap-dev-sda-with-dev-sdb
The second possibility is to change UDEV rules. The rules will be processed during system boot, and guarantee you a permanently consistent behavior. A good guide on these rules ca be found here: http://www.reactivated.net/writing_udev_rules.html

 

adduser, addgroup

#Create Users Group

ADDUSER(8)
sudo adduser <USERNAME>
NAME
       adduser, addgroup - add a user or group to the system

SYNOPSIS
       adduser [options] [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID] [--firstuid ID] [--lastuid ID] [--ingroup GROUP | --gid
       ID] [--disabled-password] [--disabled-login] [--gecos GECOS] [--add_extra_groups] [--encrypt-home] user

       adduser --system [options] [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID] [--group | --ingroup GROUP | --gid ID] [--dis‐
       abled-password] [--disabled-login] [--gecos GECOS] user

       addgroup [options] [--gid ID] group

       addgroup --system [options] [--gid ID] group

       adduser [options] user group

   COMMON OPTIONS
       [--quiet] [--debug] [--force-badname] [--help|-h] [--version] [--conf FILE]
adduser [options] [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID] [--firstuid ID] [--lastuid ID] [--ingroup GROUP | --gid
       ID] [--disabled-password] [--disabled-login] [--gecos GECOS] [--add_extra_groups] [--encrypt-home] user

 

Following commands to create, modify <USER> <GROUP>

adduser --debug --gid <GROUP_ID> <USERNAME>
usermod -u <USER_ID> <USERNAME>
usermod -G <GROUP_ID> <USERNAME>
 

Rename Hard Disk

Rename Hard Disk in Unix

ubuntu@ubuntu:~$ ll /sys/block/sda/device
lrwxrwxrwx 1 root root 0 Feb  4 14:45 /sys/block/sda/device -> ../../../2:0:1:0/
ubuntu@ubuntu:~$ ll /sys/block/sda/device/delete
--w------- 1 root root 4096 Feb  4 14:55 /sys/block/sda/device/delete
ubuntu@ubuntu:~$
ubuntu@ubuntu:~$ ll /sys/block/sdb/device
lrwxrwxrwx 1 root root 0 Feb  4 14:45 /sys/block/sdb/device -> ../../../3:0:1:0/
ubuntu@ubuntu:~$ ll /sys/block/sdb/device/delete
--w------- 1 root root 4096 Feb  4 14:57 /sys/block/sdb/device/delete
ubuntu@ubuntu:~$
sudo -i
echo offline > /sys/block/sda/device/state
echo offline > /sys/block/sdb/device/state

 

echo 1 > /sys/block/sda/device/delete
echo 1 > /sys/block/sdb/device/delete
scan this hosts hard disks
echo "- - -" > /sys/class/scsi_host/host2/scan   ( /dev/sda for my ref )
echo "- - -" > /sys/class/scsi_host/host3/scan   ( /dev/sdb for my ref )

Reference :

http://fibrevillage.com/storage/279-hot-add-remove-rescan-of-scsi-devices-on-linux

parted DEVICE unit co print unit s print

parted DEVICE unit co print unit s print

 

(parted) parted DEVICE unit co print unit s print
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular
partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular
partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
Model: ATA ST3500418AS (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 1049kB 512MB 511MB primary ext2 boot
2 513MB 500GB 500GB extended
5 513MB 500GB 500GB logical

Model: ATA ST3500418AS (scsi)
Disk /dev/sda: 976773168s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 2048s 999423s 997376s primary ext2 boot
2 1001470s 976771071s 975769602s extended
5 1001472s 976771071s 975769600s logical

(parted)

 

man parted

No manual entry for perted
owner@$:10:~$
owner@$:10:~$ man perted
No manual entry for perted
owner@$:11:~$ man parted
owner@$:12:~$ parted
WARNING: You are not superuser.  Watch out for permissions.
/dev/mapper/control: open failed: Permission denied
Failure to communicate with kernel device-mapper driver.
Incompatible libdevmapper (unknown version) and kernel driver (unknown version).
Error: No device found
Retry/Cancel? cancel
owner@$:13:~$ udo arted
The program ‘udo’ is currently not installed. To run ‘udo’ please ask your administrator to install the package ‘udo’
owner@$:14:~$ sudo parted
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) help
align-check TYPE N                        check partition N for TYPE(min|opt) alignment
help [COMMAND]                           print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END     make a partition
name NUMBER NAME                         name partition NUMBER as NAME
print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular
partition
quit                                     exit program
rescue START END                         rescue a lost partition near START and END
resizepart NUMBER END                    resize partition NUMBER
rm NUMBER                                delete partition NUMBER
select DEVICE                            choose the device to edit
disk_set FLAG STATE                      change the FLAG on selected device
disk_toggle [FLAG]                       toggle the state of FLAG on selected device
set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
unit UNIT                                set the default unit to UNIT
version                                  display the version number and copyright information of GNU Parted
(parted) version

GNU Parted 3.2

Copyright (C) 1998 – 2006 Free Software Foundation, Inc.
This program is free software, covered by the GNU General Public License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

(parted) print free
Model: ATA ST3500418AS (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type      File system  Flags
32.3kB  1049kB  1016kB            Free Space
1      1049kB  512MB   511MB   primary   ext2         boot
512MB   513MB   1048kB            Free Space
2      513MB   500GB   500GB   extended
5      513MB   500GB   500GB   logical
500GB   500GB   1073kB            Free Space

(parted) print devices
/dev/sda (500GB)
/dev/sdb (1000GB)
/dev/mapper/cryptswap1 (4282MB)
/dev/mapper/ubuntu–vg-swap_1 (4282MB)
/dev/mapper/ubuntu–vg-root (495GB)
/dev/mapper/sda5_crypt (500GB)
(parted) help
align-check TYPE N                        check partition N for TYPE(min|opt) alignment
help [COMMAND]                           print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END     make a partition
name NUMBER NAME                         name partition NUMBER as NAME
print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular
partition
quit                                     exit program
rescue START END                         rescue a lost partition near START and END
resizepart NUMBER END                    resize partition NUMBER
rm NUMBER                                delete partition NUMBER
select DEVICE                            choose the device to edit
disk_set FLAG STATE                      change the FLAG on selected device
disk_toggle [FLAG]                       toggle the state of FLAG on selected device
set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
unit UNIT                                set the default unit to UNIT
version                                  display the version number and copyright information of GNU Parted
(parted) print all
Model: ATA ST3500418AS (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End    Size   Type      File system  Flags
1      1049kB  512MB  511MB  primary   ext2         boot
2      513MB   500GB  500GB  extended
5      513MB   500GB  500GB  logical

Error: /dev/sdb: unrecognised disk label
Model: ATA TOSHIBA DT01ACA1 (scsi)
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: unknown
Disk Flags:

Model: Linux device-mapper (crypt) (dm)
Disk /dev/mapper/cryptswap1: 4282MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system     Flags
1      0.00B  4282MB  4282MB  linux-swap(v1)

Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/ubuntu–vg-swap_1: 4282MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system     Flags
1      0.00B  4282MB  4282MB  linux-swap(v1)

Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/ubuntu–vg-root: 495GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End    Size   File system  Flags
1      0.00B  495GB  495GB  ext4

Error: /dev/mapper/sda5_crypt: unrecognised disk label
Model: Linux device-mapper (crypt) (dm)
Disk /dev/mapper/sda5_crypt: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:

(parted) print devices
Backtrace has 11 calls on stack:
11: /lib/x86_64-linux-gnu/libparted.so.2(ped_assert+0x44) [0x7fd8a85fcea4]
10: /lib/x86_64-linux-gnu/libparted.so.2(+0x1c91e) [0x7fd8a860e91e]
9: /lib/x86_64-linux-gnu/libparted.so.2(+0x1ca27) [0x7fd8a860ea27]
8: /lib/x86_64-linux-gnu/libparted.so.2(+0x1e220) [0x7fd8a8610220]
7: /lib/x86_64-linux-gnu/libparted.so.2(+0xf8ba) [0x7fd8a86018ba]
6: /lib/x86_64-linux-gnu/libparted.so.2(ped_disk_set_flag+0x68) [0x7fd8a8601ed8]
5: parted(+0x72f9) [0x55aff5a7b2f9]
4: parted(interactive_mode+0x120) [0x55aff5a80ff0]
3: parted(main+0x1386) [0x55aff5a7a176]
2: /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7fd8a7dda830]
1: parted(_start+0x29) [0x55aff5a7a1d9]

You found a bug in GNU Parted! Here’s what you have to do:

Don’t panic! The bug has most likely not affected any of your data.
Help us to fix this bug by doing the following:

Check whether the bug has already been fixed by checking
the last version of GNU Parted that you can find at:

http://ftp.gnu.org/gnu/parted/

Please check this version prior to bug reporting.

If this has not been fixed yet or if you don’t know how to check,
please visit the GNU Parted website:

http://www.gnu.org/software/parted

for further information.

Your report should contain the version of this release (3.2)
along with the error message below, the output of

parted DEVICE unit co print unit s print

and the following history of commands you entered.
Also include any additional information about your setup you
consider important.

Assertion (part->disk->dev->sector_size % PED_SECTOR_SIZE_DEFAULT == 0) at ../../../libparted/labels/dos.c:589 in function
probe_filesystem_for_geom() failed.

Aborted (core dumped)
owner@$:15:~$