Installing MongoDB in Ubuntu 12.04

Unable to install latest version in Ubuntu 12.04
Refer: http://gordoncluster.wordpress.com/2013/07/12/how-to-install-mongodb-on-virtualbox-ubuntu-12-04/

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list
sudo apt-get update

We're going to specifically install an older version (you will need to run this as root):
sudo su -
apt-get install mongodb-10gen=2.2.3

The service should already be running, the output: mongodb start/running, process 2254
sudo service mongodb status | stop | start

now we just run:
mongo

The output you should see is:
MongoDB shell version: 2.2.3
connecting to: test
>

UI Tools
http://www.robomongo.org/

MongoDB Restore

$ mongorestore --drop testcms

Using canned mockup with booking flow

Refer: https://www.npmjs.org/package/canned

  • $ npm install canned
  • Unzip canned responses in bookingflow folder canned.zip
  • Update configuration.js file
    cmsUrl: 'http://localhost:3000/hal-cms',
    dsUrl: 'http://localhost:3000/hal-ds',
  • Launch canned server from root of bookingflow, default port is 3000, left here for documentation
    ./node_modules/canned/bin/canned -p 3000 ./canned

Limitation, rest calls that return images do not work properly.

Example on how to define a call

  • You will need to determine if it is a get or a post to generate the proper index file of either index.post.json or index.get.json, see the last statement of example
  • Use chrome to get the URL of the rest call, and then also to get the curl version of the rest call
  • You can string all of these together and create a bash script to do everything at once

mkdir -p /home/mruckman/Documents/bookingflow/canned/hal-ds/rest/pricing/v1.0.0/companyCode/HAL/cpp/countryCode/US

cd /home/mruckman/Documents/bookingflow/canned/hal-ds/rest/pricing/v1.0.0/companyCode/HAL/cpp/countryCode/US

curl 'https://qabook.hollandamerica.com/hal-ds/rest/pricing/v1.0.0/...

Adding Prettify JSON to Sublime

In Ubuntu, open preferences, browse packages, to get location of packages folder, and open a terminal and change into that folder

$ git clone https://github.com/dzhibas/SublimePrettyJson.git

Ubuntu: /username/.config/sublime-text-2/Packages

The use [Ctrl]+[Alt]+[j] to run the prettify command

or in iOS us [Ctrl]+[Cmd]+[j]

Refer: https://github.com/dzhibas/SublimePrettyJson

Change your Computer Name in Ubuntu

Ran into trouble when using the same VirtualBox appliance on the same network.

1. Open a terminal window.

2. Input the following command and hit Enter:
gksudo gedit /etc/hostname

3. When prompted, enter the administrator password and click the OK button.

4. The hostname file will open, displaying the current computer name. Replace the current computer name with the desired new name.

5. Click Save.

6. Close all open windows and restart your system.

After your system has restarted, it will have the new computer name.

Use Python to format JSON

Easier way to format JSON instead of JSONLINT

With Python 2.6+ you can just do:
echo '{"foo": "lorem", "bar": "ipsum"}' | python -mjson.tool

Citrix Receiver in Ubuntu

Download the receiver from the Citrix site:
http://www.citrix.com/downloads/citrix-receiver/linux/receiver-for-linux-130.html

So, you've upgraded Firefox on Ubuntu and Citrix no longer works, well do the following:

  • uninstall Firefox
  • install Firefox
  • $ sudo rm -rf /opt/Citrix/ICAClient/keystore/cacerts_old
  • reinstalled Citrix
  • redo the Citrix installation steps below
  • When you launch Citrix, make sure you ALLOW pop-ups, if asked!

Here are the steps to install Citrix for the first time:
For Ubuntu you will need to download the *.deb version and install through the software center

Now you need to get the certs to work properly in Firefox:
Refer: https://www.geekpete.com/blog/ssl-error-61-using-citrix-ica-client-on-linux/

You are going to copy the certs and create a symbolic link for all of the certs then:
$ sudo mv /opt/Citrix/ICAClient/keystore/cacerts /opt/Citrix/ICAClient/keystore/cacerts_old
$ sudo cp /opt/Citrix/ICAClient/keystore/cacerts_old/* /usr/share/ca-certificates/mozilla/
$ sudo ln -s /usr/share/ca-certificates/mozilla /opt/Citrix/ICAClient/keystore/cacerts

Using Expect Scripts to Automate Tasks (Macros)

Sample Script: sample.exp (You can run this in Ubuntu)

How to run scripts:
expect -f your-file-name.exp

Refer for possible extra goodies: http://www.thegeekstuff.com/2010/12/5-expect-script-command-line-argument-examples/

Ubuntu Installation:
$ sudo apt-get install expect
$ sudo apt-get install expect-dev

Refer: http://www.admin-magazine.com/Articles/Automating-with-Expect-Scripts

Expect is a natural and intuitive automation scripting language that operates in much the same way humans do when interacting with a system. You type in commands and expect a certain response to your command. When you receive the expected response, you enter another command and so on. Expect works in the same way, except you have to provide the script with commands and expected responses to those commands. Basically, you have to script out the entire two-way “conversation.”

You can think of an Expect script as a dialog script written for two actors: a sender and a receiver. One of the more popular activities to automate is an SSH session between two hosts, in which one host is the sender (local host) and the other is the receiver (remote host). Being able to emulate every keystroke and create a true interactive session between two systems via a script is an exciting proposition.

Expect Setup

Most Linux distributions include Expect as part of the available and installable software packages. In other words, you won’t have to download and install from source code. Use your system’s package manager to download and install Expect and any required dependencies or associated packages. For example:
$ sudo yum install expect
or
$ sudo apt-get install expect
Once you have Expect installed, you can begin writing scripts.

Creating an Interactive SSH Session

As stated previously, you must provide both sides of the conversation in your script because you’re setting up an interactive system. Look at a few essential items before diving right into a script.

To make an Expect script executable as a standalone program, you must do two things: Make the script executable, and supply the path to the script for expect . The path on my system is: /usr/bin/expect ; therefore, enter that path on the first line of your script with a preceding “shebang” (#! ):

!/usr/bin/expect -f

The -f switch tells Expect that it is reading commands from a file. The spawn command spawns or launches an external command for you. In this case, ssh to a remote host (aspen ):
spawn ssh aspen

Change the host aspen to your remote host. When you SSH to a remote system, you’re prompted for a password. This password prompt is what you “expect” from the remote system; therefore, you enter that expected response:
expect "password: "

From the local side, you have to enter your password at the password prompt. To send anything to the remote system, it must be included in double quotes and must include a hard return (\r ). Change PASSWORD to your password:

send "PASSWORD\r"
Again, you have to enter the expected response from the remote system, which in this case is a user prompt ($ ).

expect "$ "

Now that you’re logged in to the remote system, you can begin your interactive session on that remote host. The following send command issues the ps -ef |grep apache command:
send "ps -ef |grep apache\r"

Output will appear as STDOUT. After the command has executed, you’re returned to a prompt, so tell the Expect script that bit of information:
expect "$ "

Finally, send the exit command to the remote system to log out. Don’t forget that hard return (\r ):
send "exit\r"

The script in its entirety looks as follows:

!/usr/bin/expect -f

spawn ssh aspen
expect "password: "
send "PASSWORD\r"
expect "$ "
send "ps -ef |grep apache\r"
expect "$ "
send "exit\r"
Change permissions on the script so that it is executable; for example,
$ chmod 755 script.sh
and try it for yourself.

Expect Caveats

If your script hangs and doesn’t continue, try the command manually yourself and look for the response. If the remote system drops you to a prompt as its final act, then place that in your script (e.g., expect "$ " ). Be sure you have entered the hard return (\r ) inside the closing quotation mark in your send line. You might also find that your system needs two backslashes on the send line for a hard return (\r ).

Sometimes Expect scripts execute too fast, and you won’t see your expected response. If that happens, place a sleep command and a number of seconds for the command preceeding it to wait for a response, or your data might be ignored.

For example, if you connect to a remote system and there’s a delay in creating that connection, your script will continue to execute and fail because it sends commands before the remote system has time to respond.

You have to think about network delays, shell responses and system timing when scripting in Expect. Like any scripting language, Expect has its quirks, but you’ll find that it’s an easy way to automate those repetitious keystrokes and procedures. The time you spend debugging your scripts is well worth the effort.

Autoexpect

Of course, some lazy system administrators take lazy to a higher level and even cheat at writing Expect scripts by invoking a shell “watcher” or recorder script named Autoexpect. Once invoked, Autoexpect watches your every keystroke and records it to a file named, script.exp by default. You’ll almost certainly have to edit and prune this script to achieve your desired results; however, it can save hours of script debugging to have an almost complete script from which to work.

If you simply run a freshly created Autoexpect script, it will likely fail because, if you issued a command that answers your request by displaying information to the screen, the script picks up that answer, too, and copies it into the script file.

For example, if during your Autoexpect session, you type, ls , the result of that command appears in your script.exp file as well. After you’ve created a few Expect scripts by hand, you’ll appreciate the cleanup editing you have to do in an Autoexpect-created script.

To install Autoexpect, issue a command like:
$ sudo apt-get install expect-dev

You’ll likely require many more dependencies for this feature, so prepare yourself for a slight delay while everything installs.

Creating an Interactive SSH Session with Autoexpect

After installing Autoexpect and all of its required packages, you’re ready to create Expect scripts automatically by stepping through the procedures you want to automate. Using the above example, SSH to a remote system and run a
ps -ef |grep apache
command and then log out.

Invoking Autoexpect is easy:
$ autoexpect
$ autoexpect started, file is script.exp
Although it looks as if nothing has happened or is happening, every keystroke you type will be recorded into script.exp . Every STDOUT response you receive will also be copied into that same file. Your entire session is recorded – but not just recorded, it is also formatted in Expect script style. To stop recording keystrokes to your script, press Ctrl+D on your keyboard to stop Autoexpect and copy the buffer to your file.