Latest DevOps and SysAdmin Feed

What is DevOps in Simple English?

What is a System Administrator?

DevOps: In IT world, DevOps means Development Operations. The DevOps is the bridge between the developers, the servers and the infrastructure and his main role is to automate the process of delivering code to operations.
DevOps on wikipedia: is a software development process that emphasizes communication and collaboration between product management, software development, and operations professionals. DevOps also automates the process of software integration, testing, deployment and infrastructure changes.[1][2] It aims to establish a culture and environment where building, testing, and releasing software can happen rapidly, frequently, and more reliably.

DevOps Latest Feeds


DevOps Resources

  1. What is DevOps? Tackling some frequently asked questions
  2. Find Remote DevOps Jobs here.

Budget to start a web app built on the MEAN stack

I want to start a web app built on the MEAN stack (mongoDB, express.js, angular, and node.js). How much would it cost me to host this site? What resources are there for hosting websites built on the MEAN stack?

I went through the same questions and concerns and I actually tried a couple of different cloud providers for similar environments and machines.

Web Apps Feed

  1. At Digital Ocean, you can get a fully loaded machine to develop and host at $5 per month (512 MB RAM, 20 GB disk ). You can even get a $10 credit by using this link of mine.[1] It is very easy to sign up and start. Just don’t use their web console to connect to your host. It is slow. I recommend using ssh client to connect and it is very fast.
  2. GoDaddy will charge you around 8$ per month for a similar MEAN stack host (512 MB RAM, 1 core processor, 20 Gb disk ) for your MEAN Stack development.
  3. Azure use bitmani’s mean stack on minimum DS1_V2 machine (1core, 3.5 gB RAM) and your average cost will be $52 per month if you never shut down the machine. The set up is a little bit more complicated that Digital Ocean, but very doable. I also recommend ssh to connect to the server and develop.
  4. AWS also offers Bitmani’s MEAN stack on EC2 instances similar to Azure DS1V2 described above and it is around $55 per month.
  5. Other suggestions

All those solutions will work fine and it all depends on your budget. If you are cheap like me and don’t have a big budget, go with Digital Ocean and start with $10 off with this code.

Script with hash tables on windows and Linux

How to declare and write a script with hash tables on windows and linux

  • Hash tables with powershell on windows

    Declaration:
    $states=@{“Alberta” = “Calgary”; “British Columbia” = “Vancouver”; “Ontario” = “Toronto” ; “Quebec” = “Montreal”}

    Name
    _____
    Value
    _______
    Alberta Calgary
    British Columbia Vancouver
    Ontario Toronto
    Quebec Montreal

    Add new key-value in hashtable:
    $states.Add(“Manitoba”,”Winnipeg”)

    Remove key-value in hashtable:
    $states.Remove(“Manitoba”,”Winnipeg”)
    Change value in hashtable:
    $states.Set_Item(“Ontario”,”Ottawa”)
    Retrieve value in hashtable:
    $states.Get_Item(“Alberta”)
    Find key in hashtable:
    $states.ContainsKey(“Alberta”)
    Find Value in hashtable:
    $states.ContainsValue(“Calgary”)
    Count items in hashtable:
    $states.Count
    Sort items by Name in hashtable:
    $states.GetEnumerator() | Sort-Object Name -descending
    Sort items by Value in hashtable:
    $states.GetEnumerator() | Sort-Object Value -descending

  • Hash tables with perl on linux or windows

     
    Declaration:
    my %hash = (); #Initialize a hash
    my $hash_ref = {}; # Initialize a hash reference. ref will return HASH
    Clear (or empty) a hash
    for (keys %hash)
    {
    delete $hash{$_};
    }
    Clear (or empty) a hash reference
    for (keys %$href)
    {
    delete $href->{$_};
    }
    Add a key/value pair to a hash
    $hash{ ‘key’ } = ‘value’; # hash
    $hash{ $key } = $value; # hash, using variables
    Using Hash Reference
    $href->{ ‘key’ } = ‘value’; # hash ref
    $href->{ $key } = $value; # hash ref, using variables
    Add several key/value pairs to a hash
    %hash = ( ‘key1’, ‘value1’, ‘key2’, ‘value2’, ‘key3’, ‘value3’ );
    %hash = (
    key1 => ‘value1’,
    key2 => ‘value2’,
    key3 => ‘value3’,
    );

    Copy a hash
    my %hash_copy = %hash; # copy a hash
    my $href_copy = $href; # copy a hash ref
    Delete a single key/value pair
    delete $hash{$key};
    delete $hash_ref->{$key};

  • Hash tables with python on linux or windows

    Hash tables are called dictionary in python.
    Declaration:
    dict = {‘Name’: ‘Zara’, ‘Age’: 7, ‘Class’: ‘First’}
    Accessing Values
    print “dict[‘Name’]: “, dict[‘Name’]
    print “dict[‘Age’]: “, dict[‘Age’]
    Output:
    dict[‘Name’]: Zara
    dict[‘Age’]: 7
    Updating Dictionary
    dict = {‘Name’: ‘Zara’, ‘Age’: 7, ‘Class’: ‘First’}

    dict[‘Age’] = 8; # update existing entry
    dict[‘School’] = “DPS School”; # Add new entry
    Delete Dictionary Elements
    #!/usr/bin/python

    dict = {‘Name’: ‘Zara’, ‘Age’: 7, ‘Class’: ‘First’}

    del dict[‘Name’]; # remove entry with key ‘Name’
    dict.clear(); # remove all entries in dict
    del dict ; # delete entire dictionary

Source:

  1. https://technet.microsoft.com/en-us/library/ee692803.aspx
  2. http://www.cs.mcgill.ca/~abatko/computers/programming/perl/howto/hash/
  3. http://www.tutorialspoint.com/python/python_dictionary.htm

How to pipe grep on command line on windows and Linux

Let’s find how to pipe grep or find a specific string after running a command using shell, batch and powershell (windows and Linux)

  • On Linux via shell

    ls -al | grep filename

  • On Windows via powershell

    GetChildItem | Select-Object “filename”
    or
    GetChildItem | where-Object {$_ -match “filename”}

  • On Windows via batch

    Dir | findstr “filename”

JSON : JavaScript Object Notation

What is JSON : JavaScript Object Notation?

Source: https://www.json.com/

What is JSON?

JSON is a lightweight text-based open standard designed for human-readable data. It is the most widely used format for exchanging data on the web. It originates from the JavaScript language and is represented with two primary data structures: ordered lists (recognized as ‘arrays’) and name/value pairs (recognized as ‘objects’).

Why JSON?

The JSON standard is language-independent and its data structures, arrays and objects, are universally recognized. These structures are supported in some way by nearly all modern programming languages and are familiar to nearly all programmers. These qualities make it an ideal format for data interchange on the web.

JSON vs XML

The XML specification does not match the data model for most programming languages which makes it slow and tedious for programmers to parse. Compared to JSON, XML has a low data-to-markup ratio which results in it being more difficult for humans to read and write.

JSON Data Types

  • Number{ “myNum”: 123.456 }
    A series of numbers; decimals ok; double-precision floating-point format.
  • String{ “myString”: “abcdef” }
    A series of characters (letters, numbers, or symbols); double-quoted UTF-8 with backslash escaping.
  • Boolean{ “myBool”: true }
    True or false.
  • Array{ “myArray”: [ “a”, “b”, “c”, “d” ] }
    Sequence of comma-separated values (any data type); enclosed in square brackets.
  • Object{ “myObject”: { “id”: 7 } };
    Unordered collection of comma-separated key/value pairs; enclosed in curly braces; properties (keys) are distinct strings.
  • Null{ “myNull”: null }
    Variable with null (empty) value.

Unsupported Data Types

  • Undefinedvar myUndefined;
    Variable with no value assigned.
  • Datevar myDate = new Date();
    Object used to work with dates and times.
  • Errorvar myError = new Error();
    Object containing information about errors.
  • Regular Expressionvar myRegEx = /json/i;
    Variable containing a sequence of characters that form a search pattern.
  • Functionvar myFunction = function(){};
    Variable containing a block of code designed to perform a particular task.

JSON cheat sheet

Example1: Mixed Data Types

var myObject = {
“myNumber”: 123.456,
“myString”: “abcdef”,
“myBool”: true,
“myArray”: [ “a”, “b”, “c”, “d” ],
“myObject”: { “id”: 7 },
“myNull”: null
};

Example2: Send HTTP POST request with JSON to a http://url with the following string fields: ‘first_name’, ‘last_name’, ’email’, ‘phone’,’urls’

curl -X POST -d ‘{“first_name”: “John”, “last_name”: “Doe”, “email”: “johndoe@email.com”, “phone”: “000-000-0000″,”urls”: [“https://djamga.com”,”http://enoumen.com”,”http://twitter.com/enoumen”]}’ http:/url -H ‘Content-Type: application/json’

Remove all empty lines in a file

How to Remove all empty lines in a file on Linux and Windows?

Remove empty lines from file.txt via Linux command line

  • Option 1: sed -i ‘/^$/d’ file.txt
  • Option 2: awk ‘NF > 0’ file.txt > output.txt
  • Option 3: perl -i.backup -n -e “print if /\S/” file.txt
  • Option 4: grep . file.txt > output.txt

Remove empty lines from file.txt using Powershell script on Windows

  • (gc file.txt) | ? {$_.trim() -ne “” } | set-content file.txt
  • Linux Boot process

    Let’s describe Linux Boot Process:

    BIOS Basic INPUT/OUTPUT System.
    Executes MBR
    MBR Master Boot Record
    Executes GRUB
    GRUB Grand Unified Bootloader
    Executes kernel
    KERNEL Kernel
    Executes /sbin/init
    INIT Init
    Executes Run level programs
    Run Level Run Level Programs are executed from /etc/rc.d/rc*.d/
    • As power comes up the BIOS is given control
    • BIOS runs self tests, usually including cursory memory tests.
    • The BIOS then loads the first sector of the disk to be used for booting and transfers control to it.
    • The MBR code varies. One version will chain to the code in the first sector of the boot partition (Windows), another will load a bootloader. Windows boot proceeds from code and information in the boot partition.
    • The bootloader chooses kernel location and version
    • The bootloader prepares kernel and initrd image in memory, transfers control to kernel
    • Loading kernel modules
    • Discovering hardware and load additional kernel modules to support it
    • Looking for disks
    • R/O mount of / partition so that it can potentially be checked and repaired
    • init process spawn
    • /etc/inittab read and executing
    • Mounting all FSes from /etc/fstab
    • runlevels running (based on default runlevel in /etc/inittab) or another init method such as systemd or upstart
    • rc.local
    • login prompt

    Source:

    1. http://unix.stackexchange.com/questions/27034/discribe-in-details-tha-boot-process-of-any-linux-system
    2. http://www.thegeekstuff.com/2011/02/linux-boot-process/
    3. Watch video here
    4. http://www.slideshare.net/dominiquec/understanding-the-boot-process

    Monitor Macbook

    How to Monitor Macbook with one single command?

    $sudo sysdiagnose -f ~/Desktop/

    The result is a compressed file named sysdiagnose_YYYY.MM.DD_HH-MM-SS-TTTT.tar.gz and it contains the following:
    Accessibility
    BluetoothTraceFile.pklg
    DiagnosticMessages
    Etienne’s SystemConfiguration
    airport_info.txt
    apsd-status.txt
    bc_stats.txt
    bootstamps.txt
    brctl.tar.gz
    breadcrumbs.txt
    crashes_and_spins
    darwinup.txt
    dig-results.txt
    disks.txt
    diskutil.txt
    error_log.txt
    filecoordination_dump.txt
    footprint-all.txt
    fs_usage.txt
    fsck_hfs_user.log
    fsck_hfs_var.log
    gpt.txt
    ifconfig.txt
    ioreg
    ipconfig.txt
    kextstat.txt
    launchctl-list.txt
    locale.txt
    logs
    lsappinfo.txt
    lsmp.txt
    lsof.txt
    lsregister.txt
    microstackshots
    microstackshots_lastday.txt
    microstackshots_lasthour.txt
    microstackshots_lastminute.txt
    mount.txt
    netstat
    nfsstat.txt
    odutil.txt
    pluginkit.txt
    pmset_everything.txt
    powermetrics.txt
    ps.txt
    ps_thread.txt
    reachability-info.txt
    resolv.conf
    scutil.txt
    smcDiagnose.txt
    spindump.txt
    stackshot-last-sym.log
    sysctl.txt
    sysdiagnose.log
    system_profiler.spx
    talagent.txt
    taskinfo.txt
    thermal.txt
    top.txt
    var_run_resolv.conf
    vm_stat.txt
    zprint.txt

    List only regular file names in a directory

    How to List only regular file names in a directory on Linux and Windows

    Listing regular files in a directory without including . and .. files.


    • On Linux

      Solution 1:$ ls -p | grep -v /
      Solution 2: $ ls -F | grep -v ‘[/@=|]’
      Solution 3: $for list in `ls` ; do ls -ld $list | grep -v ^d > /dev/null && echo $list ; done ;
      Solution4:$ for list in `ls` ; do ls -ld $list | grep ^d > /dev/null || echo $list ; done ;
      Solution5 (exclude sym links):$ for list in `ls` ; do ls -ld $list | grep -v ^l > /dev/null && echo $list ; done ;


    • On Windows

      Solution 1: dir /a-d /b >..\File_List.txt

    Set Date and time via command line

    Let’s find out how to set Date and time via command line on linux and windows:

    • On Linux via terminal

      System time (Must have sudo privilege)
      date -s ‘2015-07-28 15:27:30’
      Hardware time
      Let’s set the hardware clock to the current system time:
      hwclock –systohc

    • On Windows via command prompt terminal

      System time (Must have Administrator privilege)
      date
      The current date is: 07/28/2015
      Enter the new date: (mm-dd-yy)_
      time
      The current time is: 15:34:03.44
      Enter the new time: _