1.04.2015

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

11.24.2014

Get Latest Records SQL

Using this SQL:

SELECT sb1.date, sb1.branch, sb1.build
FROM stable_builds sb1
INNER JOIN (
    SELECT max(date) date, branch
    FROM stable_builds
    GROUP BY branch
) AS sb2
ON sb1.branch = sb2.branch
AND sb1.date = sb2.date
ORDER BY date DESC

Data:
Date Branch Build   
2014-11-24 5.6 460049
2014-11-19 5.6 459641
2014-11-16 5.6 459347

Output:
Date Branch Build   
2014-11-24 5.6 460049

10.01.2014

Rails - Separate Seeds Using Seedbank

Seedbank gives your Rails seed data a little structure. Create seeds for each environment, share seeds between environments and specify dependencies to load your seeds in order. All nicely integrated with simple rake tasks. This is how I quickly used it:
1.  Put in Gemfile:
gem "seedbank"

2. Install
$ bundle install

3. Create the specific seed file:
$ vi db/seeds/performance_translations.seeds.rb
translations = [
  ["r-high-0001","1-read high-generation"],
  ["r-high-0008","8-read high-generation"],
  ["r-high-0016","16-read high-generation"]
]
translations.each do |int, ext|
  PerformanceTranslation.find_or_create_by_internal(internal: int, external: ext)
end

4. Run via rake
$ rake db:seed:performance_translations

6.05.2014

Schedule rake using cron on rvm environment

Little tricky to get this going. The key is knowing rvm environment.
$ rvm env --path
/auto/home3/delacs/.rvm/environments/ruby-2.0.0-p353@RailsDev
For rvm, basic command line tools like gem, rake and ruby are in the wrappers directory.
$ crontab -l
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
HOME=/auto/home3/delacs
RAILS_ENV=development

0 7 * * * /bin/bash -l -c 'source ~/.bash_profile' && cd $HOME/Documents/projects/monweb_management && $HOME/.rvm/wrappers/ruby-2.0.0-p353@RailsDev/rake perfdb:get_baselines >> $HOME/logs/db.import.log 2>&1

5 7 * * * /bin/bash -l -c 'source ~/.bash_profile' && cd $HOME/Documents/projects/monweb_management && $HOME/.rvm/wrappers/ruby-2.0.0-p353@RailsDev/rake perfdb:get_published_runs  >> $HOME/logs/db.import.log 2>&1

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