Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

5.15.2015

Configure VLAN tagging via CLI

1. Create VLAN interface
# ip link add link eth4 name eth4.2030 type vlan id 2030

2. Assign IP
# ifconfig eth4.2030 11.0.20.1 netmask 255.255.240.0

3. Make sure new interface is enabled
# ifconfig eth4.2030 up

4. Check 
# ifconfig eth4.2030
eth4.2030 Link encap:Ethernet  HWaddr 90:E2:BA:6D:B5:95
          inet addr:11.0.20.1  Bcast:11.0.31.255  Mask:255.255.240.0
          inet6 addr: fe80::92e2:baff:fe6d:b595/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1046 (1.0 KiB)  TX bytes:468 (468.0 b)

5. Remove VLAN
# ip link delete eth4.2030

4.29.2015

Sync Clock Automatically on CentOS

Got it from here.
1. Install
# yum install ntp ntpdate ntp-doc

2. Turn on service
# chkconfig ntpd on

3. Sync one time
# ntpdate pool.ntp.org

4. Configure ntpd
# vi /etc/ntp.conf
Add public servers
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org

5. Start the NTP server. The following will continuously adjusts system time from upstream NTP server. No need to run ntpdate:
# /etc/init.d/ntpd start

2.13.2015

Install different versions of Perl on Linux using Perlbrew

Got from here and here. What is perlbrew.
1. Install perfbrew
$ curl -kL http://install.perlbrew.pl | bash

2. Modify .bashrc and add:
source ~/perl5/perlbrew/etc/bashrc

3. Initialize
$ perlbrew init

4. Select mirror
$ perlbrew mirror

5. See what's available
$ perlbrew available
  perl-5.20.1
  perl-5.18.4
  perl-5.16.3
  perl-5.14.4

6. Install perls
$ perlbrew install perl-5.20.1  # did not work for Centos 6.5
$ perlbrew --notest install perl-5.20.1

7. See what were installed
$ perlbrew list

8. Swith to an installation and set it as default
$ perlbrew switch perl-5.20.1

9. Temporarily use another version only in current shell.
$ perlbrew use perl-5.20.1
$ perl -v

10. Or turn it off completely. Useful when you messed up too deep. Or want to go back to the system Perl.
$ perlbrew off

11. Use 'switch' command to turn it back on.
$ perlbrew switch perl-5.20.1

12. Exec something with all perlbrew-ed perls
$ perlbrew exec -- perl -E 'say $]'

13. Install cpanm
$ perlbrew install-cpanm

14. Install cpan modules
$ cpanm install File::Copy::Recursive XML::Simple etc

1.21.2015

Use iperf to measure network link bandwidth

Nice writeup on how to use iperf. Another example, writeup.
1. Install iperf
$ sudo yum install iperf

2. Start server on another system:
$ iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 10.1.1.1 port 5001 connected with 10.0.0.1 port 46699
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.3 sec   107 MBytes  87.7 Mbits/sec

3. Start client from your system specifying server ip:
$ iperf -c 10.1.1.1
------------------------------------------------------------
Client connecting to 10.1.1.1, TCP port 5001
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 10.0.0.1 port 46699 connected with 10.1.1.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.1 sec   107 MBytes  89.0 Mbits/sec

4. Use options, e.g., -t duration, -i interval between measurements
$ iperf -c 10.1.1.1 -t 20 -i 2
------------------------------------------------------------
Client connecting to 10.1.1.1, TCP port 5001
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 10.0.0.1 port 46761 connected with 10.1.1.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 2.0 sec  17.6 MBytes  73.9 Mbits/sec
[  3]  2.0- 4.0 sec  22.5 MBytes  94.4 Mbits/sec
[  3]  4.0- 6.0 sec  21.2 MBytes  89.1 Mbits/sec
[  3]  6.0- 8.0 sec  22.6 MBytes  94.9 Mbits/sec
[  3]  8.0-10.0 sec  22.5 MBytes  94.4 Mbits/sec
[  3] 10.0-12.0 sec  21.2 MBytes  89.1 Mbits/sec
[  3] 12.0-14.0 sec  22.6 MBytes  94.9 Mbits/sec
[  3] 14.0-16.0 sec  22.5 MBytes  94.4 Mbits/sec
[  3] 16.0-18.0 sec  21.2 MBytes  89.1 Mbits/sec
[  3] 18.0-20.0 sec  22.5 MBytes  94.4 Mbits/sec
[  3]  0.0-20.1 sec   217 MBytes  90.6 Mbits/sec

Just want to take note: Bandwidth vs Throughput

Bandwidth : Refers how fast a device can send data over a single communication channel.
Throughput: Refers how fast a device is actually sending data over the communication channel.

1.20.2015

Network 2 ubuntu systems via crossover cable

Got from here.
1. Pick one of the computers to be the server. If one computer has a connection to the Internet use that as the server.

2. On the server click the network indicator and chose "Edit Connections...". Select the Ethernet connection then click the "Edit..." button. Go to the IPv4 tab and change "Method" from "Automatic (DHCP)" to "Shared to other computers".

3. Connect the two computers together using an Ethernet cable. The second computer will get assigned an IP address from the server and get access to the Internet.

If you have old hardware you may need to make sure the Ethernet cable is a crossover cable. Modern hardware automatically does the crossover.
==============================================
hostname:mango, os:Ubuntu 14.10 Utopic Unicorn
==============================================
ASRock Z97 Extreme6 LGA 1150 Intel Z97 HDMI SATA 6Gb/s USB 3.0 ATX Intel Motherboard
Intel Core i7-4790 Haswell Quad-Core 3.6GHz LGA 1150 84W Desktop Processor Intel HD Graphics 4600
Team Xtreme 16GB (2 x 8GB) 240-Pin DDR3 SDRAM DDR3 2400 Desktop Memory
OCZ ARC 100 ARC100-25SAT3-240G 2.5" 240GB SATA III MLC Internal Solid State Drive
Western Digital WD Blue WD10EZEX 1TB 7200 RPM 64MB Cache SATA 6.0Gb/s 3.5" Internal Hard Drive
ENERMAX Ostrog GT ECA3280A-BR Black / Red Steel / Plastic ATX Mid Tower Computer Case

Install and setup Samba on Ubuntu

Got from here.
1. Install samba
$ sudo apt-get update
$ sudo apt-get install samba

2. Set a password for samba user
$ sudo smbpasswd -a samdc
New SMB password:
Retype new SMB password:
Added user samdc.

3. Create a directory to be shared
$ sudo mkdir /data1/staging

4. Make sure user has access
$ sudo chown samdc:samdc /data1/staging

5. Make a backup copy of smb.conf
$ cp /etc/samba/smb.conf ~

6. Edit smb.conf
$ sudo vi /etc/samba/smb.conf
Add this to the very end of the file:
[staging]
path = /data1/staging
available = yes
valid users = samdc
read only = no
browseable = yes
public = yes
writable = yes

7. Restart samba
$ sudo service smbd restart

8. Check smb.conf for any syntax errors
$ testparm

9. To access network share
Linux:
smb://<HOST_IP_OR_NAME>/<folder_name>/
smb://10.42.0.1/staging/

Windows:
\\<HOST_IP_OR_NAME>\<folder_name>\
\\10.42.0.1\staging\

==============================================
hostname:mango, os:Ubuntu 14.10 Utopic Unicorn
==============================================
ASRock Z97 Extreme6 LGA 1150 Intel Z97 HDMI SATA 6Gb/s USB 3.0 ATX Intel Motherboard
Intel Core i7-4790 Haswell Quad-Core 3.6GHz LGA 1150 84W Desktop Processor Intel HD Graphics 4600
Team Xtreme 16GB (2 x 8GB) 240-Pin DDR3 SDRAM DDR3 2400 Desktop Memory
OCZ ARC 100 ARC100-25SAT3-240G 2.5" 240GB SATA III MLC Internal Solid State Drive
Western Digital WD Blue WD10EZEX 1TB 7200 RPM 64MB Cache SATA 6.0Gb/s 3.5" Internal Hard Drive
ENERMAX Ostrog GT ECA3280A-BR Black / Red Steel / Plastic ATX Mid Tower Computer Case

1.07.2015

Prepare FC19 for RabbitMQ development

Got RabbitMQ install from here and here.

Install Erlang

1. $ sudo yum install erlang

Install RabbitMQ from RPM

2. $ sudo rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc 3. $ sudo rpm -Uvh http://www.rabbitmq.com/releases/rabbitmq-server/v3.4.3/rabbitmq-server-3.4.3-1.noarch.rpm (or grab latest here)

Configure RabbitMQ SSL

TODO: outline steps

Install RabbitMQ management console

4. $ sudo rabbitmq-plugins enable rabbitmq_management

Open Firewall

5. $ firewall-cmd --permanent --add-port=5672/tcp 6. $ firewall-cmd --reload 7. $ setsebool -P nis_enabled 1

Start RabbitMQ as a daemon by default

8. $ sudo chkconfig rabbitmq-server on # To start the service: /sbin/service rabbitmq-server start # To stop the service: /sbin/service rabbitmq-server stop # To restart the service: /sbin/service rabbitmq-server restart # To check the status: /sbin/service rabbitmq-server status

Open RabbitMQ management UI

10. Browse to http://localhost:15672/

Install Bunny (Ruby Development)

9. $ gem install bunny Fetching: amq-protocol-1.9.2.gem (100%) Successfully installed amq-protocol-1.9.2 Fetching: bunny-1.6.3.gem (100%) Successfully installed bunny-1.6.3 2 gems installed Enjoy!

1.06.2015

My .aliases

My collection of bash knick knacks.
alias 2proj='cd /auto/home/samdc/projects'

# cd to a directory that is relative to 2proj directory
function 2p() { 2proj && cd $@ ;}

# list resources files
# use: res filename*
function res() { 2proj && cd common/resources/ && ls -l */$@ ; }

# diff color
alias colorize='~/bin/p4c.rb'

1.05.2015

Things to do after installing Ubuntu 14.10 Utopic Unicorn

I got this from here, here, here and here.
1. Enable partner repository
$ sudo sed -i "/^# deb .*partner/ s/^# //" /etc/apt/sources.list && apt-get update

2. Download and Install GetDeb and PlayDeb
$ echo "Downloading GetDeb and PlayDeb" &&
wget http://archive.getdeb.net/install_deb/getdeb-repository_0.1-1~getdeb1_all.deb http://archive.getdeb.net/install_deb/playdeb_0.3-1~getdeb1_all.deb &&
echo "Installing GetDeb" &&
sudo dpkg -i getdeb-repository_0.1-1~getdeb1_all.deb &&
echo "Installing PlayDeb" &&
sudo dpkg -i playdeb_0.3-1~getdeb1_all.deb &&
echo "Deleting Downloads" &&
rm -f getdeb-repository_0.1-1~getdeb1_all.deb &&
rm -f playdeb_0.3-1~getdeb1_all.deb

3. Add PPAs (Personal Package Archives)
$ sudo add-apt-repository -y ppa:videolan/stable-daily
$ sudo add-apt-repository -y ppa:otto-kesselgulasch/gimp
$ sudo add-apt-repository -y ppa:gnome3-team/gnome3
$ sudo add-apt-repository -y ppa:webupd8team/java
$ sudo add-apt-repository -y ppa:webupd8team/y-ppa-manager
$ sudo add-apt-repository -y ppa:transmissionbt/ppa
$ echo 'deb http://download.videolan.org/pub/debian/stable/ /' | sudo tee -a /etc/apt/sources.list.d/libdvdcss.list &&
echo 'deb-src http://download.videolan.org/pub/debian/stable/ /' | sudo tee -a /etc/apt/sources.list.d/libdvdcss.list &&
wget -O - http://download.videolan.org/pub/debian/videolan-apt.asc|sudo apt-key add -

4. Update and upgrade
$ sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade

5. Install essentials
$ sudo apt-get install synaptic vlc gimp gimp-data gimp-plugin-registry gimp-data-extras y-ppa-manager bleachbit openjdk-7-jre oracle-java8-installer flashplugin-installer unace unrar zip unzip p7zip-full p7zip-rar sharutils rar uudeview mpack arj cabextract file-roller flac faac faad sox ffmpeg2theora libmpeg2-4 uudeview mpeg3-utils mpegdemux liba52-dev mpeg2dec vorbis-tools id3v2 mpg321 mpg123 libflac++6 totem-mozilla icedax lame libmad0 libjpeg-progs libdvdcss2 libdvdread4 libdvdnav4 ubuntu-restricted-extras ubuntu-wallpapers*

6. Install additional drivers
Open Software & Updates > Additional Drivers, install as needed

7. Install Google Chrome
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb &&
sudo dpkg -i google-chrome-stable_current_amd64.deb &&
rm -f google-chrome-stable_current_amd64.deb

8. Install VirtualBox
Verify if virtualbox packages are included in multiverse repository
$ apt-cache policy virtualbox
virtualbox:
   Installed: (none)
   Candidate: 4.3.18-dfsg-1
   Version table:
   4.3.18-dfsg-1 0
        500 http://in.archive.ubuntu.com/ubuntu/ utopic/multiverse amd64 Packages

Update repository then install
$ sudo add-apt-repository multiverse
$ sudo apt-get update
$ sudo apt-get install virtualbox

9. Install TrueCrypt
To install:
sudo add-apt-repository ppa:stefansundin/truecrypt
sudo apt-get update
sudo apt-get install truecrypt

To automatically grant TrueCrypt sudo powers, edit sudoers with "sudo visudo" and add this (important: add it to the end of the file!):
your_username ALL=(ALL) NOPASSWD:/usr/bin/truecrypt

Using "sudo visudo" makes sure you don't damage the file and prevent your system to boot. Never edit the sudoers file directly. If you're wondering why TrueCrypt exits when you hide it, go to Preferences » Background Task » uncheck "Exit when there are no mounted volumes".

10. Install vim with perl/python/ruby support
$ sudo apt-get remove vim-tiny vim vim-nox
$ sudo apt-get build-dep vim
$ sudo apt-get install mercurial
$ hg clone https://vim.googlecode.com/hg/ vim74
$ cd vim74
$ ./configure --enable-perlinterp --enable-pythoninterp --enable-rubyinterp --enable-cscope  --with-features=huge --prefix=/usr
$ sudo make
$ sudo make install

11. Adjust privacy
System Settings > Security & Privacy
Files & Applications - turn OFF
Search - turn OFF

12. Disable system crash reports
$ sudo vim /etc/default/apport
Change to: enabled=0
$ sudo service apport stop

13. Show menus in window's title bar
System Settings > Appearance > Behavior

14. Change display scale
System Settings ~ Displays ~ Scale for menu and title bars ~ adjust to 0.875

15. Install TweakTools or Unity Tweak Tools
$ sudo apt-get install unity-tweak-tool gnome-tweak-tool
Open Unity Tweak Tool and select "Minimize single window applications on click"

16. Install Skype

17. Install dupeGuru
$ sudo add-apt-repository ppa:hsoft/ppa
$ sudo apt-get update
$ sudo apt-get install dupeguru*

18. Install Unison
$ sudo apt-get install unison unison-gtk

19. To watch silverlight based video streams (HBO Go, etc)
$ sudo add-apt-repository ppa:mjblenner/ppa-hal
$ sudo apt-get update
$ sudo apt-get install hal
$ cd ~/.adobe/Flash_Player
$ rm -rf NativeCache AssetCache APSPrivateData2
$ sudo add-apt-repository ppa:pipelight/stable
$ sudo apt-get update
$ sudo apt-get install --install-recommends pipelight-multi
$ sudo pipelight-plugin --update
$ sudo pipelight-plugin --enable silverlight

20. Card reader support
$ sudo apt-get install exfat-fuse exfat-utils

21. Clean up
echo "Cleaning Up" &&
sudo apt-get -f install &&
sudo apt-get autoremove &&
sudo apt-get -y autoclean &&
sudo apt-get -y clean
==============================================
hostname:mango, os:Ubuntu 14.10 Utopic Unicorn
==============================================
ASRock Z97 Extreme6 LGA 1150 Intel Z97 HDMI SATA 6Gb/s USB 3.0 ATX Intel Motherboard
Intel Core i7-4790 Haswell Quad-Core 3.6GHz LGA 1150 84W Desktop Processor Intel HD Graphics 4600
Team Xtreme 16GB (2 x 8GB) 240-Pin DDR3 SDRAM DDR3 2400 Desktop Memory
OCZ ARC 100 ARC100-25SAT3-240G 2.5" 240GB SATA III MLC Internal Solid State Drive
Western Digital WD Blue WD10EZEX 1TB 7200 RPM 64MB Cache SATA 6.0Gb/s 3.5" Internal Hard Drive
ENERMAX Ostrog GT ECA3280A-BR Black / Red Steel / Plastic ATX Mid Tower Computer Case

1.04.2015

Add and Delete Users on Ubuntu 14.10

1. Create user
samdc@mango:~$ sudo adduser raqueldc
[sudo] password for samdc: 
Adding user `raqueldc' ...
Adding new group `raqueldc' (1001) ...
Adding new user `raqueldc' (1001) with group `raqueldc' ...
Creating home directory `/home/raqueldc' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for raqueldc
Enter the new value, or press ENTER for the default
 Full Name []: Raquel
 Room Number []: 
 Work Phone []: 
 Home Phone []: 
 Other []: 
Is the information correct? [Y/n] 

2. Delete user
Delete account:
samdc@mango:~$ sudo userdel newuser
Delete home directory
samdc@mango:~$ sudo rm -rf /home/newuser
==============================================
hostname:mango, os:Ubuntu 14.10 Utopic Unicorn
==============================================
ASRock Z97 Extreme6 LGA 1150 Intel Z97 HDMI SATA 6Gb/s USB 3.0 ATX Intel Motherboard
Intel Core i7-4790 Haswell Quad-Core 3.6GHz LGA 1150 84W Desktop Processor Intel HD Graphics 4600
Team Xtreme 16GB (2 x 8GB) 240-Pin DDR3 SDRAM DDR3 2400 Desktop Memory
OCZ ARC 100 ARC100-25SAT3-240G 2.5" 240GB SATA III MLC Internal Solid State Drive
Western Digital WD Blue WD10EZEX 1TB 7200 RPM 64MB Cache SATA 6.0Gb/s 3.5" Internal Hard Drive
ENERMAX Ostrog GT ECA3280A-BR Black / Red Steel / Plastic ATX Mid Tower Computer Case

Move home dir to another drive

Got it from here.
First install the drive, then follow these steps:
1. Find UUID of the partition
root@mango:~# blkid 
/dev/sdb1: UUID="8b1e1564-d7b6-4ef4-9ffd-d7d191251cc2" TYPE="ext4" PARTUUID="0835b8cd-01"

2. Modify fstab
root@mango:~# vim /etc/fstab
Add this line
UUID=8b1e1564-d7b6-4ef4-9ffd-d7d191251cc2 /media/home          ext4    defaults        0       2

3. Create temporary mount point
root@mango:~# mkdir /media/home

4. Reload fstab
root@mango:~# mount -a

5. Copy /home to new partition
root@mango:~# rsync -aXS --exclude='/*/.gvfs' /home/. /media/home/.

6. Prepare fstab for the switch
root@mango:/home/samdc# vim /etc/fstab
Modify this line to:
UUID=8b1e1564-d7b6-4ef4-9ffd-d7d191251cc2 /home          ext4    defaults        0       2

7. Do the switch
root@mango:~# cd / && sudo mv /home /old_home && sudo mkdir /home

8. Reload fstab
root@mango:/# mount -a

9. Delete old home
root@mango:/# rm -r /old_home

10. Reboot
==============================================
hostname:mango, os:Ubuntu 14.10 Utopic Unicorn
==============================================
ASRock Z97 Extreme6 LGA 1150 Intel Z97 HDMI SATA 6Gb/s USB 3.0 ATX Intel Motherboard
Intel Core i7-4790 Haswell Quad-Core 3.6GHz LGA 1150 84W Desktop Processor Intel HD Graphics 4600
Team Xtreme 16GB (2 x 8GB) 240-Pin DDR3 SDRAM DDR3 2400 Desktop Memory
OCZ ARC 100 ARC100-25SAT3-240G 2.5" 240GB SATA III MLC Internal Solid State Drive
Western Digital WD Blue WD10EZEX 1TB 7200 RPM 64MB Cache SATA 6.0Gb/s 3.5" Internal Hard Drive
ENERMAX Ostrog GT ECA3280A-BR Black / Red Steel / Plastic ATX Mid Tower Computer Case

Install a new hard drive

Got it from here.
1. Partition disk
samdc@mango:/dev$ sudo fdisk /dev/sdc

Welcome to fdisk (util-linux 2.25.1).
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.
Created a new DOS disklabel with disk identifier 0xb73af669.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1953525167, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-1953525167, default 1953525167): 

Created a new partition 1 of type 'Linux' and of size 931.5 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

2. Format disk
samdc@mango:/dev$ sudo mkfs -t ext4 /dev/sdc1
mke2fs 1.42.10 (18-May-2014)
Creating filesystem with 244190390 4k blocks and 61054976 inodes
Filesystem UUID: 6dba4379-83fa-4288-b390-98574bc24bb2
Superblock backups stored on blocks: 
 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
 102400000, 214990848

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done     

3. Modify reserved space
samdc@mango:/dev$ sudo tune2fs -m 1 /dev/sdc1
tune2fs 1.42.10 (18-May-2014)
Setting reserved blocks percentage to 1% (2441903 blocks)

4. Label disk
samdc@mango:/dev$ sudo e2label /dev/sdc1 DataDisk2

5. Create mount point
samdc@mango:/dev$ sudo mkdir /data2

6. Mount the drive
Automatic mount at boot:
root@mango:/dev# vim /etc/fstab
Add this line (find out UUID of the disk via blkid):
UUID=6dba4379-83fa-4288-b390-98574bc24bb2 /data2           ext4    defaults 0       2
For changes to take effect:
root@mango:/dev# mount -a

Manually mount/unmount:
sudo mount /dev/sdc1 /data2
sudo umount /data2
==============================================
hostname:mango, os:Ubuntu 14.10 Utopic Unicorn
==============================================
ASRock Z97 Extreme6 LGA 1150 Intel Z97 HDMI SATA 6Gb/s USB 3.0 ATX Intel Motherboard
Intel Core i7-4790 Haswell Quad-Core 3.6GHz LGA 1150 84W Desktop Processor Intel HD Graphics 4600
Team Xtreme 16GB (2 x 8GB) 240-Pin DDR3 SDRAM DDR3 2400 Desktop Memory
OCZ ARC 100 ARC100-25SAT3-240G 2.5" 240GB SATA III MLC Internal Solid State Drive
Western Digital WD Blue WD10EZEX 1TB 7200 RPM 64MB Cache SATA 6.0Gb/s 3.5" Internal Hard Drive
ENERMAX Ostrog GT ECA3280A-BR Black / Red Steel / Plastic ATX Mid Tower Computer Case

Find out what disks are in the system

root@mango:/dev# sfdisk -l

Disk /dev/sda: 29185 cylinders, 255 heads, 63 sectors/track
sfdisk: Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Units: cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1   *      0+  27135-  27136- 217963520   83  Linux
/dev/sda2      27135+  29185-   2050-  16464897    5  Extended
/dev/sda3          0       -       0          0    0  Empty
/dev/sda4          0       -       0          0    0  Empty
/dev/sda5      27135+  29185-   2050-  16464896   82  Linux swap / Solaris

Disk /dev/sdb: 121601 cylinders, 255 heads, 63 sectors/track

Disk /dev/sdc: 121601 cylinders, 255 heads, 63 sectors/track

root@mango:/dev# lshw -class disk
  *-disk                  
       description: ATA Disk
       product: OCZ-ARC100
       physical id: 0.0.0
       bus info: scsi@0:0.0.0
       logical name: /dev/sda
       version: 1.00
       serial: A22L1061449007331
       size: 223GiB (240GB)
       capabilities: partitioned partitioned:dos
       configuration: ansiversion=5 sectorsize=512 signature=2a960743
  *-disk
       description: ATA Disk
       product: WDC WD10EZEX-00B
       vendor: Western Digital
       physical id: 0.0.0
       bus info: scsi@1:0.0.0
       logical name: /dev/sdb
       version: 1A01
       serial: WD-WCC3F3NFSS65
       size: 931GiB (1TB)
       configuration: ansiversion=5 sectorsize=4096
  *-cdrom
       description: DVD-RAM writer
       product: iHAS124   E
       vendor: ATAPI
       physical id: 0.0.0
       bus info: scsi@3:0.0.0
       logical name: /dev/cdrom
       logical name: /dev/cdrw
       logical name: /dev/dvd
       logical name: /dev/dvdrw
       logical name: /dev/sr0
       version: 4L08
       capabilities: removable audio cd-r cd-rw dvd dvd-r dvd-ram
       configuration: ansiversion=5 status=nodisc
  *-disk
       description: ATA Disk
       product: WDC WD10EZEX-00B
       vendor: Western Digital
       physical id: 0.0.0
       bus info: scsi@4:0.0.0
       logical name: /dev/sdc
       version: 1A01
       serial: WD-WCC3F1CX4JKE
       size: 931GiB (1TB)
       configuration: ansiversion=5 sectorsize=4096

root@mango:/dev# lsblk -f
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda                                                      
├─sda1 ext4         1987feef-7ad1-4e00-8578-9559d8aff148 /
├─sda2                                                   
└─sda5 swap         c17c259d-e3a8-4220-9f0d-9df4af33fa34 [SWAP]
sdb                                                      
sdc                                                      
sr0                                                      

root@mango:/dev# blkid
/dev/sda1: UUID="1987feef-7ad1-4e00-8578-9559d8aff148" TYPE="ext4" PARTUUID="2a960743-01" 
/dev/sda5: UUID="c17c259d-e3a8-4220-9f0d-9df4af33fa34" TYPE="swap" PARTUUID="2a960743-05" 

root@mango:/dev# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Jan  4 08:24 1987feef-7ad1-4e00-8578-9559d8aff148 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jan  4 08:24 c17c259d-e3a8-4220-9f0d-9df4af33fa34 -> ../../sda5

==============================================
hostname:mango, os:Ubuntu 14.10 Utopic Unicorn
==============================================
ASRock Z97 Extreme6 LGA 1150 Intel Z97 HDMI SATA 6Gb/s USB 3.0 ATX Intel Motherboard
Intel Core i7-4790 Haswell Quad-Core 3.6GHz LGA 1150 84W Desktop Processor Intel HD Graphics 4600
Team Xtreme 16GB (2 x 8GB) 240-Pin DDR3 SDRAM DDR3 2400 Desktop Memory
OCZ ARC 100 ARC100-25SAT3-240G 2.5" 240GB SATA III MLC Internal Solid State Drive
Western Digital WD Blue WD10EZEX 1TB 7200 RPM 64MB Cache SATA 6.0Gb/s 3.5" Internal Hard Drive
ENERMAX Ostrog GT ECA3280A-BR Black / Red Steel / Plastic ATX Mid Tower Computer Case

New System 2015

I built a new system this winter break...

==============================================
hostname:mango, os:Ubuntu 14.10 Utopic Unicorn
==============================================
ASRock Z97 Extreme6 LGA 1150 Intel Z97 HDMI SATA 6Gb/s USB 3.0 ATX Intel Motherboard
Intel Core i7-4790 Haswell Quad-Core 3.6GHz LGA 1150 84W Desktop Processor Intel HD Graphics 4600
Team Xtreme 16GB (2 x 8GB) 240-Pin DDR3 SDRAM DDR3 2400 Desktop Memory
OCZ ARC 100 ARC100-25SAT3-240G 2.5" 240GB SATA III MLC Internal Solid State Drive
Western Digital WD Blue WD10EZEX 1TB 7200 RPM 64MB Cache SATA 6.0Gb/s 3.5" Internal Hard Drive
ENERMAX Ostrog GT ECA3280A-BR Black / Red Steel / Plastic ATX Mid Tower Computer Case

12.13.2014

Perforce Client Setup

I got it from here.
1. Export environment variable
$ export P4CONFIG=.p4config

2. Create workspace directory
$ cd /auto/home/delacs/projects/autoselect_feature
$ mkdir code

3. Create p4 config file, name of client will be 'delacs-autoselect-feature'
$ vi .p4config
P4CLIENT=delacs-autoselect-feature
P4PORT=server.domain.com:1666

4. Create the client
$ p4 client

In text editor:
Client: delacs-autoselect-feature
Root:  /auto/home/delacs/projects/autoselect_feature
View: //tools/main/perf/scripts/scheduler/... //delacs-autoselect-feature/code/scheduler/...
      //tools/parser/... //delacs-autoselect-feature/code/parser/...

5. Now, let's pull down code from perforce
$ p4 sync

5.08.2014

Backup Dir and Files in Linux Using Tar and Bash

1. Create a bash script
$ vi backup.sh
#!/bin/bash
# This is a script the creates a backup of
# monitor instances: .../monitor/inst => .../monitor/backup

DATE=`date +"%Y%m%d"`
TIMESTAMP=`date +"%Y/%m/%d %T"`
FILENAME="inst_backup_$DATE.tar.gz"
SRCDIR="inst"
DESDIR="backup"

tar -cpzf $DESDIR/$FILENAME $SRCDIR

if [ $? -eq 0 ]; then
    echo "$TIMESTAMP: Backup success: $FILENAME"
else
    echo "$TIMESTAMP: Backup error: $?"
fi

# Any backup older than 30 days are deleted
find ./$DESDIR -type f -mtime +30 -delete -printf "$TIMESTAMP: Deleted %16f\n"

for tar:
c - create
p - preserve file and dir permission
z - compress file
f - target filename

2. Schedule with cron
$ crontab -e
0 5 * * * cd $HOME/scheduler/monitor && ./backup.sh >> $HOME/scheduler/monitor/backup/logs/monitor.backup.log 2>&1

This would schedule a backup at 5am everyday

10.09.2013

How to add Launcher in Gnome for Fedora 19

Create a .desktop file:
$ sudo vi /usr/share/applications/aptana-studio-3.desktop
Add this content:
[Desktop Entry]
Name=Aptana Studio 3
Exec=/usr/local/bin/Aptana_Studio_3/aptana
Icon=/usr/local/bin/Aptana_Studio_3/icon.xpm
Type=Application
Categories=Development

10.03.2013

VNC Server Setup on Fedora 19

I followed this post to setup my VNC Server. Specific to my setup I had to update my /etc/systemd/system/vncserver@:1.service so that it will wait for autofs for my home directory:
After=syslog.target network.target autofs.service
Then I had to open up the ports for VNC as follows:
$ sudo firewall-cmd --permanent --zone=public --add-service=vnc-server

9.24.2013

Bash Keyboard Shortcuts

Ctrl + A        Go to the beginning of the line you are currently typing on
Ctrl + E        Go to the end of the line you are currently typing on
Ctrl + L        Clears the Screen, similar to the clear command
Ctrl + U        Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H        Same as backspace
Ctrl + R        Let’s you search through previously used commands
Ctrl + C        Kill whatever you are running
Ctrl + D        Exit the current shell
Ctrl + Z        Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W        Delete the word before the cursor
Ctrl + K        Clear the line after the cursor
Ctrl + T        Swap the last two characters before the cursor
Esc + T         Swap the last two words before the cursor
Alt + F         Move cursor forward one word on the current line
Alt + B         Move cursor backward one word on the current line
Tab             Auto-complete files and folder names

9.17.2013

Linux Cheat Sheet

1. Find Out Linux Distribution Name and Version:
$ cat /etc/∗-release
Red Hat Enterprise Linux Server release 5 (Tikanga)
2. Use scp (Cygwin) to transfer files:
>scp -r [user_name]@[host_name or host_ip]:[Path to your directory] [target_path_dir]
>scp -r root@server.domain.com:/tmp/example.zip .
>scp -r user@your.server.example.com:/path/to/foo /home/user/Desktop/
from local to remote server:
>scp file* root@server.domain.com:/tmp
3. Copy files from a linux server to another linux server
rsync -auv -e ssh --progress source_folder/ useraccount@machine.whatever.com:/destination_folder/
4. Find files using 'find'
#find files from current directory and subdirectories that matches mon*
$ find . -name mon\*

#find files from current directory and subdirectories displaying the full path
$ find `pwd` -name koala\*
#or
$ find `pwd` | grep koala

#find files older than 90 days and move to another directory
$ find /home/perf-builder/deploy -maxdepth 1 -mtime +90 -type f -exec mv "{}" /perflogs/deploy_package_archive/ \;

#find files that are writable by anyone
$ find -maxdepth 1 -type f -perm /222

#find files that are writable by their owners
$ find -maxdepth 1 -type f -perm /200
5. Delete environment variable
$ env | grep rvm
OLDPWD=/home/samdc/.rvm
$ unset OLDPWD
6. Set environment variable
$ export PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
7. Monitor log file as the file grows using tail
$ tail -f /home/sammydc/logs/request.log
8. Search a directory for files containing certain string
$ grep -r "192.168.1.5" /etc/
$ grep -E "whatever" -r .   - recursive on current dir and subdirs
# multi-line grep
$ grep -Ezl "FC_count\s+2.*autoselect\s+yes.*client_os_version_linux\s+CentOS 6.5.*fc_switch\s+ls-dur3-mds2.*motherboard_product_name\s+.*C240.*use_for_group\s+Perf" *.cfg
# grep from different directories from July 21 – July 28
grep 'caught exception: ERROR' /mnt/perfresults/*/logs/2016072[1-8]_*/controller_log
9. This will show process id, user, command and arguments:
$ ps -e -o "pid,user,comm,args"
10. Cat a bunch of files at once
$ for f in /var/log/*.log; do cat $f; done
11. Iterate thru a list and apply operation
Copy a file to multiple destination
$ for FILE in {544..579}; do cp perf-c440 perf-c$FILE; done

Ping several clients
$ for CLIENT in client1 client2 client3; do ping $CLIENT -c2; done
12. Filter using grep with regex
$ ps -efw | grep -E '5\.5.*dd670'
13. List directories up to 3 levels down, then filter
$ ls -d ./*/*/* | grep 416041
14. Get number of cpus
$ cat /proc/cpuinfo | grep processor | wc -l
15. Get memory info
$ cat /proc/meminfo
16. Get disks info
$ cat /proc/partitions
$ df -H
17. How to determine biggest directories/files occupying disk
$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda5             26011288  24703036         0 100% /
/dev/sda1               202219     63562    128217  34% /boot
$ df -BG  (in GigaBytes)
Filesystem           1G-blocks      Used Available Use% Mounted on
/dev/dd_dg0_0p15            2G        2G        1G  68% /
/dev/dd_dg0_0p14            5G        4G        2G  72% /ddr
/dev/dd_dg0_0p13           30G       30G        0G 100% /ddr/var

$ du -a /home | sort -n -r | head -n 10
14259824        /home
14259052        /home/delacs
14259048        /home/delacs/scheduler
14256188        /home/delacs/scheduler/ctl
9382796 /home/delacs/scheduler/ctl/run_request.log
3238172 /home/delacs/scheduler/ctl/resourcedb.log
1036148 /home/delacs/scheduler/ctl/requestdb.log
569516  /home/delacs/scheduler/ctl/update_resource_status.log
29492   /home/delacs/scheduler/ctl/www_index.log
2056    /home/delacs/scheduler/resources

$ du -h /home | sort -h -r | head -n 10 (human readable form)
$ du -ahx / | sort -h -r | head -n 50 (exclude mounted directories)
18. Which processes take so much... Memory
$ ps -e -o pid,vsz,command | sort -n -r -k 2 | head -n 20
22796 345320 /usr/sbin/httpd
22799 344772 /usr/sbin/httpd
22907 344392 /usr/sbin/httpd
27749 242936 run_request_id_20140614_0800_mweb_dur
26515 217668 run_request_id_20140725_1738_mweb_dur
20061 217476 run_request_id_20140724_1600_mweb_dur
27748 215428 run_request_id_20140614_0800_mweb_dur
...
CPU
$ ps -eo pcpu,pid,user,args | sort -k1 -r -n | head -20
 8.8  9341 ioperf   /usr/bin/python /home/ioperf/maestro-production/cloudapi/pcrun.py --noTty --logLevel DEBUG -s /tmp/tmpsap5Fn/cfg.json -w /tmp/tmpsap5Fn/cfg.json -r /tmp/tmpsap5Fn/cfg.json --scriptDir /home/ioperf/maestro-production --resultDirBase /data/maestro_prod/vsan-fio
 7.0 29457 ioperf   /usr/bin/python /home/ioperf/maestro-production/cloudapi/pcrun.py --noTty --logLevel DEBUG -s /tmp/tmpUvSJTh/cfg.json -w /tmp/tmpUvSJTh/cfg.json -r /tmp/tmpUvSJTh/cfg.json --scriptDir /home/ioperf/maestro-production --resultDirBase /data/maestro_prod/vsan-fio
 0.4  8817 root     /usr/bin/etserver --daemon --cfgfile=/etc/et.cfg
...
19. Find files and delete them
The basic find command syntax is:
find dir-name criteria action
dir-name : - Defines the working directory such as look into /tmp/
criteria : Use to select files such as "*.sh"
action : The find action (what-to-do on file) such as delete the file.

$ find . -name ".nfs000000000006a8b200000062" -exec rm -rf {} \;

Options:
-name "FILE-TO-FIND" : File pattern.
-exec rm -rf {} \; : Delete all files matched by file pattern.
20. Echo string with a tab and append to end of a file
$ echo -e "autoselect\tyes" >> perf-c576
21. Count number of directories
$ echo 201404*/ | wc
22. Prepend contents of a file to another file
echo -e "`cat list.idx.forcopy`\n$(cat list.idx)" > list.idx
23. Script execution time
$ time ./monitor_regression.pl
...
Output
...
real    0m57.766s
user    0m0.444s
sys     0m0.805s
24. NFS mount
# mount -t nfs -o rw,nosuid,nodev,tcp,intr,nolock perfresultsSC:/backup /mnt/perfresultsSC/
25. Time sync
# ntpdate time-server-name-or-ip
26. Start process in background
$ ./my_process >std.txt 2>err.txt &
$ ./my_process >std.txt 2>&1 & (both stdout and stderr goes to the same file)
$ ./my_process >/dev/null 2>err.txt & (don't care about output, but stderr is recorded)
27. Monitor CPU & Memory utilization
Get CPU utilization every 2 minutes and run forever
$ mpstat -P ALL 120 > mpstat.log &
Get memory utilization every 2 minutes in 2 weeks
$ sar -r 120 10080 > sar.log &
27. Put currently running process in the background
$ Ctrl+Z
$ bg
# be able to exit out of ssh connection without affecting the running process
$ disown -h
27. Memory usage of a process, units in MB
$ smem -P server.rb
  PID User     Command         Swap      USS      PSS      RSS 
 2176 samdc    ruby server.rb     0   240052   241281   246296 
28. Create a tarball
$ tar -cvf openssh.deploy.tar file1 file2
$ tar -zcvf archive-name.tar.gz directory-name
$ tar -zcvf archive-name.tar.gz directory-name --remove-files (to remove original directory and files)
29. View tarball contents
$ tar -tvf openssh.deploy.tar
30. Extract tarball
$ tar -xvf openssh.deploy.tar
31. Kill processes at once
$ ps -efw | grep rvc | grep '1  ' | awk '{print $2}' | xargs -I{} kill -9 {}
Safer...
$ ps -ewf | grep rvc | grep 10.92.81.163 | awk '{print $2}' | xargs -I{} kill -9 {}
30. Rename files in directory at once
$ for file in *.log; do mv "$file" "$file.old"; done
31. How to remove all empty directories in a subtree
$ find ROOTDIR -type d -empty -delete
e.g.
$ find /mnt/maestro/maestro_prod/vsan-fio/15278 -type d -empty -delete
32. Find out how much space files occupy in a directory
$ du -bch