Sunday 6 March 2016

Get Mac OS X System Information from Terminal

Hii! Guys lets come back today on another topic related to Apple Mac OS X. Correct me if am wrong, the first thing you would after purchasing your new Macbook or iMac is double-check the system information right?

Typically you would click the Apple logo on top left -> About this Mac -> System Report. Well could you get the same information from command line? Yes you can!

Open terminal and just type the following :

system_profiler

It will list the system information in a matter of few seconds. You could also filter the command to get only specific information by piping to a grep command.

For eg :

system_profiler | grep Memory

system_profiler | grep Processor

system_profiler | grep CPU

Saturday 5 March 2016

Maven : mvn package in Eclipse

Guys, as you maybe aware the command "mvn package" creates a package and stores it in the target directory. On the other side if you run "mvn install" it will create a package and then store it in your local repository.

I assume you have created a project from the archetypes from command line and then converted it to a Maven project after importing it in Eclipse.

Make sure the pom.xml has packaging set to jar by default. You could also change the package to war if needed.

Now simple right click the project to choose Run as -> Run Configurations.


Here you can specify the goals. In this case, we just want to create a simple package. So do this :


As you see, we also get various options for e.g. to build offline, skip tests, debug output etc. Now just enter the goals "clean package" and click Run.

You'll see that after a while a jar package gets created in the target directory of the project. Similarly if you run "clean install", it will install the jar to your local repository location. Make sure to double check the timestamp of the package from Terminal.

GRE GMAT CAT Wordlist - Set 1

Hello guys. From today onwards, apart from the regular technical posts, I'll also be starting a new series - GRE GMAT CAT Wordlists. From time to time I'll try to post unique sets of words with their meanings. The objective is to aid you guys for preparation of competitive exams like GRE GMAT CAT etc. The wordlists would really help you gain a competitive edge in the verbal and comprehension sections of the exams.

FYI these are inspired by Barron's GRE word reference. The only difference is that Barron's words  are sorted in alphabetical sequence. While I'll try to mix and match the words in any random sequence. Hope it helps.

Here are some casual tips to improve your English :
  • Try to memorise the words and their meanings. 
  • Try to use these words and construct sentences. If you read an article from a newspaper or magazine, try to incorporate the newly learned words in it and reconstruct a certain phrase or statement.
  • Definitely use flashcards. They help a lot in memorising the words.
  • Read lots of books and articles.
  • Watch lots of English movies and television soaps.
  • Socialise a lot and network around, all while speaking in English.
  • (Optional) Date around, flirt a lot and chat in English. Helps build confidence ;)
Ok let's get going guys. Here's the first set of 10 words for today.

amalgamate : combine together, unite
bard : poet
cadaver : dead body, corpse
clandestine : secret, something that's done secretly
adulterate : make something impure and of inferior quality, contaminate
altercation : noisy quarrel, noisy argument
belated : delayed
lacklustre : dull, boring, lacking shine or gloss
intangible : vague
gravity : seriousness, of importance

How to debug shell / bash scripts

While executing the bash scripts, if you want to debug them i.e you want to trace the exact sequence of steps that get executed, continue reading this post below.

Just below the shebang line on top of every script, type this :

set -x

That's it.

Let's take the example of killing a process / application using shell script that we saw in our previous post. Assuming you have opened the application - TextWrangler and want to close it using a bash script.

#!/bin/bash
set -x


kill -9 `ps -ef | grep TextWrangler | awk '{print $2}'`;

Now here's the output for the same :

++ ps -ef
++ grep TextWrangler
++ awk '{print $2}'

+ kill -9 24677 24678 24682

Note that 24677 24678 and 24682 are all PID's of all processes associated with TextWrangler. In this way you can track the flow of the script in which the tasks get executed. Debugging can be of great help if you have a complex flow of program and need to identify the sequence of steps in which they are executed.

Friday 4 March 2016

Kill process or application using Apache Ant

Hello friends. In our last post we saw how to execute a shell script from Apache Ant. In today's post lets see if we could use Ant to kill some running processes.

For example lets open the TextWrangler app. Now lets try to close it using Ant build.

Consider a shell script kill-wrangler.sh as below :

kill -9 `ps -ef | grep TextWrangler | awk '{print $2}'`;

Now we'll execute the above bash script and kill the corresponding PID (process ID) for the TextWrangler app using the Ant build. Consider the following build.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="AntBuildTest" default="kill-process" basedir=".">

<target name="kill-process">
<exec executable="/bin/bash">
<arg value="kill-wrangler.sh"/>
</exec>
</target>


</project>

In this we execute the above bash script kill-wrangler.sh and close the application. You could grep (search) the running processes for any other program/string. For instance you could kill some Java process or maybe stop some application. Okay guys, signing out for now. Will post some more cool stuff in the forthcoming days. Stay tuned...

Wednesday 2 March 2016

How to open Terminal from within Eclipse on Mac OS X

In Eclipse, from the Help menu -> Eclipse Marketplace, lookup for Terminal. Install the plugin TM Terminal that you'll come across as below:


Once installed, simply mention the shell interpreter location in the Preferences for e.g. /bin/bash and also choose the initial working directory as either your User Home or Eclipse Workspace.


Now go to Window -> Show View and choose Terminal to show it within Eclipse and click the following blue button to open a new session.


This way you can run shell scripts from within Eclipse itself. Cheers!

Tuesday 1 March 2016

Call shell script from Apache Ant build on Mac OS X

Guys, you might come across some situations where you need to invoke shell and execute a bash script while building a project using Apache Ant. In today's example let's see how to run a shell script from within an Ant build.

For illustration, lets create a simple bash script to list the disk usage of our system. Let's name this file as "DiskUsage.sh"

#!/bin/bash

# Sample shell script to be invoked from an Ant build

echo "Disk usage is as follows : \n"
echo "=========================== \n"


df -h

Now let's create a simple build-test.xml using the exec command to invoke the shell as follows :

<?xml version="1.0" encoding="UTF-8"?>

<project name="AntBuildTest" default="call-shell" basedir=".">

<target name="call-shell">
<exec executable="/bin/bash">
<arg value="DiskUsage.sh"/>
</exec>
</target>


</project>

Run the ant build from command line as ant -f build-test.xml. Note that the shell script and build.xml happen to be at the same location/hierarchy within the project. If your shell script lies elsewhere, you may perhaps want to refer to its path in the build.properties instead.

You could also invoke the "expect" scripting prompt in a similar fashion to execute an expect script that we discussed in our earlier post.

More information on the exec can be read at the official Ant manual.
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker