Tuesday, December 17, 2013

Linux Console Output to File (both STDOUT&STDERR)

ls -l 2>&1 | tee output.txt

bash.sh 2>&1 | tee output.txt

2>&1 = direct both STDOUT & STDERR to the same place
| = pipe = sends command before into something after
tee = command line program that write console output (stdout) to console and to a file
output.txt = file name for STDOUT & STDERR

Post Specific to Ubuntu Linux

Monday, December 16, 2013

Node.js Console Output (STDOUT) to File

I solved by rewriting console.log function.  This was the quickest way to convert stdout object to a string without adding another module.

var fs = require('fs');
var sys = require('sys');
var exec = require('child_process').exec;
function puts(error, stdout, stderr){
    var oldWrite = process.stdout.write;
    process.stdout.write = function(d) {
        fs.writeFile('shellOutput.txt', d);
        oldWrite.apply(this, arguments);

exec('ls -al', puts);

node output.js

Git Clone Develop Branch

git clone -b develop https://git@github.com/username/myproject.git

-b = branch
develop = my branch name

Wednesday, December 11, 2013

Node.js Forever Error Log

1. forever list

2. open logfile to see last error:

cd .forever/
cat QJb-.log (the .log file with most recent date)

Node.js and Forever module crashing on Ubuntu 12.04


Tuesday, December 3, 2013

Add FAVICON to Website Tab

FAVICON = image in left corner of website tab of browser

1.  Favicon Generator

2.  Add this code inside <head> </head> of each HTML of website:

<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">


Style Horizontal Line HTML, CSS

<hr style="color:red;background-color:red;height:1px;border:none;"/>

HTML <hr> = horizontal line
CSS style= Supports All Browsers

Thursday, November 21, 2013

Restrict Google Search Crawl

STEPS or CODE GENERATOR to Restrict Search Engines

1.  New File named:  robots.txt

2.  Add this text:

# robots.txt generated at http://www.mcanerin.com
User-agent: *
Disallow: /

3.  Copy to Web Server Root (in /var/www/ for apache on linux)

NOTE: This will restrict all search engines from crawling and indexing your web server so that it doesn't show up on Google or Bing results.  #3 is specific to Linux Ubuntu with Apache Web Server installed.

Blocking search engines with robots.txt does not affect Google Analytics.  As long as the analytics UA tracking code script is still in the HTML file, Google Analytics will track visits. 

Thursday, October 31, 2013

Shortcut Link Folder in Ubuntu Linux Server

ln -s /FolderPath/ FolderLinkName

Shortcut = Soft Link = Symbolic Link
Note:  this creates a folder with chosen "FolderLinkName" in the current directory

Cyberduck Permission Denied (Editing file in Ubuntu Server)

SOLUTION: Change owner of problem folder & it's contents to the username logging in through Cyberduck through terminal on Ubuntu Server ...

sudo chown -R username folder/*

Permission denied (SSH_FX_PERMISSION_DENIED...

  • Cyberduck, FileZilla 
  • Editing files on Ubuntu Linux Server from Mac
  • Note " /* " changes permission of everything in the folder

Linux 32-bit or 64-bit

uname -a

32-bit RESULT
Linux discworld 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux

64-bit RESULT
Linux discworld 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

Wednesday, October 30, 2013

Saturday, October 26, 2013

Download Youtube Video

1.  Firefox Add-on:  Download Youtube Videos as MP4s > Install

2.  Open Youtube Video in Firefox

3.  Download button appears below video (choose MP4 or FLV)

GOAL:  Save videos on computer & iPhone


Wednesday, October 9, 2013

Angular Bootstrap Expand/Collapse Button

jsFIDDLE (abstracts out body tag and external references)

CODE (in single file)


  • Expand/collapse wasn't working on Cloud9IDE
  • Couldn't get Bootstrap expand/collapse button working, so I jumped to angular


Friday, September 27, 2013

FileZilla: Add Amazon Server

PURPOSE:  To copy/transfer files between personal computer & amazon server.

1.  Download SSH Key (.pem) from Amazon Web Services

2.  FileZilla > Preferences > SFTP

  • Add keyfile...
  • Allow FileZila to convert .pem to .ppk

3.  File > Site Manager

  • Add Host IP & User
  • Protocol:  SFTP - SSH File Transfer Protocol

4.  Connect

Wednesday, September 25, 2013

Execute a Unix Shell Command in Node.js

var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {sys.puts(stdout)}
exec("ls -la", puts);

2 - create newFile.js
3 - copy in text above & save
4 - type shell command:  node newFile.js
5 - output of "command" inside of exec() will show in console

Wednesday, September 18, 2013

Wednesday, September 11, 2013

UnMount NFS Network File Share on Ubuntu

sudo: unmount: command not found

sudo umount 


Tuesday, September 10, 2013

Cloud9IDE node app Not Starting

ERROR in Cloud9IDE
throw er; // Unhandled 'error' event                                                                                                                                                
Error: you may be using the wrong PORT & HOST for your server app 
Node: use 'process.env.PORT' as the port and 'process.env.IP' as the host in your scripts. 

Node app is running through another console session.  When attempting to start your new node app session, cloud9 errors about port/host.

SOLUTION 1:  Logout of Cloud9 Session through bottom Console twice


SOLUTION 2:  Find Node Process ID & Kill it

1. top to show processes
2. k to trigger Kill
3. Open up node app in another tab while watching for the node process to jump to top in top processes.  Mine was 23682 (your's will be different).
4. 23682
5. 15 to confirm killing
6. Go back to node directory & node app 

SOLUTION 3:  Find Node Process ID & Kill it
(this one's more difficult to find the node-openshift process)

netstat -lpn

find node process:
tcp        0      0*                   LISTEN      23682/node-openshif

kill -15 23682

        throw er; // Unhandled 'error' event                                                                                                                                                
 Cloud9  Error: you may be using the wrong PORT & HOST for your server app                                                                                                                  
         Node: use 'process.env.PORT' as the port and 'process.env.IP' as the host in your scripts. See also https://c9.io/site/blog/2013/05/can-i-use-cloud9-to-do-x/                      
Error: listen EADDRINUSE                                                                                                                                                                    
    at errnoException (net.js:906:11)                                                                                                                                                       
    at Server._listen2 (net.js:1044:14)                                                                                                                                                     
    at listen (net.js:1066:10)                                                                                                                                                              
    at Server.listen (net.js:1132:5)                                                                                                                                                        
    at Object. (/var/lib/stickshift/521509f54382ec067d000240/app-root/data/590355/platform/app.js:55:24)                                                                         
    at Module._compile (module.js:456:26)                                                                                                                                                   
    at Object.Module._extensions..js (module.js:474:10)                                                                                                                                     
    at Module.load (module.js:356:32)                                                                                                                                                       
    at Function.Module._load (module.js:312:12)                                                                                                                                             
    at Function.Module.runMain (module.js:497:10)       

Linux Set Timezone by Command Line: Ubuntu 12.04 Server

1.  FIND Timezone Identifier (example:  America/New_York)


2.  SET Timezone: Type 2 Commands below

echo "America/New_York" | sudo tee /etc/timezone

sudo dpkg-reconfigure --frontend noninteractive tzdata

3.  TEST Timezone


Nodejs Javascript Set Date/Timezone


process.env.TZ = 'America/New_York';


= system time in miliseconds since 1 Jan 1970 UTC

new Date().getHours();


Set timezone in function:
process.env.TZ = 'America/New_York';

Momentjs Node Module

Apache Internet User


www-data is the default user that asks apache questions for a webpage on your server

Find out yours by running 'top', accessing your website, then see which user uses apache2:

Tuesday, September 3, 2013

Install Apache onto Ubuntu 12.04 with 1 command

sudo apt-get install lamp-server^
remember the caret (^) at the end of the command

sudo apt-get install lamp-server
Reading package lists... Done

Building dependency tree       

Reading state information... Done
E: Unable to locate package lamp-server

LAMP Server is a collection of open source software used to create a web server. The collection consists of:
  • Linux – the operating system
  • Apache – the web server
  • MySQL – the database system
  • PHP – the programming language

Thursday, August 29, 2013

Synchronous vs. Asynchronous [Node.js]

SYNCHRONOUS = waits for one line of code to finish before moving on to another task

  • example:  PHP 

ASYNCHRONOUS = moves on to another task before it finishes that line of code

  • example:  Node.js (asynchronous by default, sychronous can be forced with certain functions & callbacks)

Tuesday, August 27, 2013

Install .iso to VMware Fusion

  1. Download .iso of operating system (ubuntu desktop for this)
  2. Open VMWare > File > New
  3. "New Virtual Machine Assistant" 
    1. Create a custom virtual machine
    2. Continue
    3. Choose Operating System & Version
    4. Customize Settings (if you want to change1GB memory & 20GB storage defaults)
  4. VMware will attempt to boot from CD and then fail
  5. Menu Bar > Virtual Machine > CD/DVD (IDE) > Choose Disc or Disc Image... > Select .iso file
  6. Menu Bar > Virtual Machine > CD/DVD (IDE) > Connect CD/DVD
  7. Wait about a minute for Operating System to start through VMware
  8. Install

This post is specifically for installing Ubuntu 12.04 into VMware Fusion 5.0 on Mac OSX without the CD/DVD Drive.

Friday, August 23, 2013

Javascript/Node Replace Space with Dash or Space

var phrase = phrase.replace(/\s+/g, '-');

var phrase = phrase.replace(/\s+/g, ');


Git Reset Remote Branch with Local Branch

Start New/Fresh Local Repository

Download Master Code

git clone https://github.com/user/repository.git

Create New Local Develop Branch & Switch to it (-b) 

git checkout -b develop

Force Overwrite (-f) Remote Develop Branch with Newly Created Local Develop Branch

git push -f github develop

This FORCES an overwrite of remote branch files while retaining commit history, NO merging.

Git Reset Local Branch with Remote Branch

git fetch --all
git reset --hard origin/branch
git fetch downloads the latest from remote without trying to merge or rebase anything. Then 
git reset resets the master branch to what you just fetched

This FORCES an overwrite of local files, NO merging.

Sunday, July 21, 2013

Github Copy Public Key from Terminal to Github.com


cat ~/.ssh/id_rsa.pub

cat shows contents using word wrap in terminal

ssh-keygen -t rsa -C "user@email.com"
Your public key has been saved in ~/.ssh/id_rsa.pub
-  needing to copy a public key from terminal & paste into gitub.com
-  with nano, line in terminal is too long to highlight everything on one screen
- xclip from github tutorial did not work

Friday, July 19, 2013

FileZilla Error Folder Write Permission


sudo chown -R bitnami:daemon /opt/bitnami/apache2/htdocs
sudo find /opt/bitnami/apache2/htdocs -type f | xargs chmod 644
sudo find /opt/bitnami/apache2/htdocs -type d | xargs chmod 755

Error:  open for write: permission denied
mkdir: cannot create directory `test': Permission denied

Wednesday, July 10, 2013

Favorite Linux Commands

cd = change directory / navigate to another file

ls = list folder contents

Ctrl + E = end of line

Ctrl + A = beginning of line

Ctrl + L = clear terminal

Ctrl + K = cut line (delete & copy)

View Processes

Search Processes
ps -ax | grep -i skype

Kill Processes
kill 41258

Cloud9IDE SSH Workspace to Amazon EC2

CLOUD9 from c9.io

1.  Create New Workspace > SSH

2.  Hostname:  ec2-184-72-92-230.compute-1.amazonaws.com

3.  Username:  ubuntu

4.  Copy SSH Key

AMAZON from your local terminal

5.  ssh -i PrivateKey.pem ubuntu@ec2-184-72-92-230.compute-1.amazonaws.com

  • Note:  PrivateKey.pem must locally be in same folder as this ssh command

6.  nano ~/.ssh/authorized_keys

7.  Paste SSH key from Cloud9

INSTALL NODE.JS from terminal inside amazon vm

8.  sudo apt-get update
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

CLOUD9 from c9.io

9.  Login Test

10.  Apply

Clone/Copy Virtual Machine on VMware

vSphere Client 5.1
  1. Click on the host > Configuration tab
  2. Select Hardware > Storage to display the datastores
  3. Right-click on the datastore with the VM you want to clone > Browse Datastore
  4. Create a new folder in the store
  5. Right click on the VM folder and select Copy (must be done in the right pane of the Datastore Browser)
  6. Paste the VM to a new sub folder (otherwise the VM will overwrite itself)
  7. Once copied, rename and move the folder if desired
  8. Select the .vmx file within the cloned VM and select 'Add to Inventory'
**VMware needs to bring their software up to 2013.  This process reminds me of 1990s software.

Friday, June 21, 2013

Linux Run a .sh File

sh file.sh
bash file.sh

git submodule update Permission Denied

git submodule update

fatal: Needed a single revision
Unable to find current revision in submodule path 'cookbooks/R'
  • rm -rf cookbooks/R

Permission denied (publickey)
fatal: The remote end hung up unexpectedly


Wednesday, June 19, 2013

Show Web Folder Contents (Apache Directory Listing)

GOAL: To allow internet access/permission of folder contents.  To solve, we have to edit the Apache configuration file.  Post specific to:  Linux, Ubuntu, Bitnami

1.  Find Apache Configuration File: apache2.conf or httpd.conf
  • /etc/apache2/apache2.conf
  • /etc/httpd/httpd.conf
  • /opt/bitnami/apache2/conf/httpd.conf

2.  nano /etc/apache2/apache2.conf

3.  Add code & Save:
<Directory /var/www/domain.com/folder>
Options Indexes FollowSymLinks
4.  sudo /etc/init.d/apache restart 
OR  sudo sh /opt/bitnami/ctlscript.sh restart apache2
FollowSymLinks  |  Multiviews

Thursday, June 13, 2013

Monday, June 10, 2013

Set User as Admin / View All Admins [Ubuntu Linux]

PROBLEM:  I want to add see if a user in ubuntu linux is an administrator.

  • Ultimate Administrator in Linux = root
  • Administrator Group in Linux = sudo


Set Admin:

adduser <username> sudo

View Admins:

sudo apt-get install members
members --all <sudo>

Check if Specific User is an Admin:

groups <user>
if "sudo" shows up, this user is an admin

Increase Size of Amazon Instance


  1. ssh into instance
  2. df -h
    1. This command shows a human readable version of space used.  More info about Linux/Unix Free Disk Space
    2. /dev/xvda1 = your Elastic Block Storage
  1. AWS Management Console > EC2
  2. Instances > Right Click Instance that needs resized > Stop
  3. Volumes > Select Instance Volume > Actions > Create Snapshot (note the snapshot name & description)
    1. see newly created snapshot in Snapshots
  4. Volumes > Note Availability Zone & Attachment Information (e.g. /dev/sda1) of Existing Instance
  5. Right Click Existing, smaller size, Volume > Detach Volume
  6. Volumes > Create Volume
    1. Type: standard
    2. Size:  choose desired larger size
    3. Availability Zone:  choose same as noted in 4
    4. Snapshot:  choose created snapshot in 3
    5. Yes, Create
  7. Right Click New, larger sized, Volume > Attach Volume
    1. Instance desired (note that instance will not show up if volume was not setup in the same Availability Zone are original)
    2. Device:  e.g. /dev/sda1/ (your's may be different) under Attachment Information from above (if not correct, you will get an error when trying to restart instance)
  8. Instances > Right Click Instance that needs resized > Start
  9. Reassign IP of Instance
    1. Elastic IPs > Associate Address

Mac: Screenshot then Highlight part of it

SKITCH by Evernote = best way to take a screenshot then highlight part of it on Mac

Part of Screen:  Shift + Cmd + 5
Fullscreen:  Shift + Cmd + 6

(best mac equivalent of Window's Snipping Tool)

Wednesday, May 29, 2013

Install Node.js on Ubuntu 12.04

sudo apt-get update
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

DO NOT INSTALL NODE:  sudo apt-get install node
running this 'node' in terminal will result in:  axconfig: port 1 not active 

node package in ubuntu = Amateur Packet Radio Node program:  accepts & connects to radio frequencies / protocols

Remove Amateur Node & install Node.js:
  1. sudo apt-get remove --purge node
  2. sudo apt-get clean
  3. Install Nodejs using steps above

Wednesday, May 22, 2013

Linux Install .run File

1.  sudo chmod +x example.run
2.  sudo ./example.run

Bitnami to VMware vSphere Client

import a Bitnami Virtual Machine (Operating System & Software stack) into ESXi using vSphere Client (VMware's virtualization software)

1.  Download a Bitnami Virtual Machine

These ERRORS in vSphere Client caused this post:
    • New > Virtual Machine > No way to choose Bitnami... Operating System choices are limited to VMware dropdown list
    • Deploy OVF Template... > Choose Bitnami OVF > Error
    • Host > Summary Tab > Right Click on Datastore, Uploading > Error when powering on
2.  Download & Install VMware vCenter Converter Standalone

3.  Convert Machine (in VMware vCenter Converter Standalone)

4.  Source = "Backup image or third party virtual machine"

5.  Browse to Bitnami's .VMX

6.  Next

7.  Type:  VMware Infrastructure virtual machine
     Server:  IP of ESXi server hardware/host
     Username:  root
     Password:  (your set password)

8.  Next > Follow defaults until finished

9.  Update Memory & Hard Drive to desired size

10.  Power On VM from vSphere Client

I hope VMware produces a better product than this very soon.  vSphere feels and works like 1990s software.  


vSphere CONSOLE 
Mac Click: Control + fn + alt