Tuesday, 29 October 2013

Copy using Scp in shell script using expect !!

Here is simple script to copy using scp and expect ,
We are creating a simple script on the fly and run that script

cat > /tmp/copy_from_remote.sh << EOF
#!/usr/bin/expect
set timeout 10
log_user 0
spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $REMOTE_CREDENTIAL_USERNAME@$host_name :$

expect "*?assword"
send "$CREDENTIAL_PASSWORD\r"
expect "*100\%*\r"
EOF

chmod 777 /tmp/copy_from_remote.sh
sh /tmp/copy_from_remote.sh

Once script is ready need to run .
 For details we can add exp_internal 1 in the expect script
 Need to disable host key checking and known host file .



Tuesday, 22 January 2013

Some gdb tricks you should know


gdb is an amazingly versatile and flexible tool, and mastering it can save you huge amounts of time when trying to debug problems in your code, here is some unusual commands for gdb

1) Logging :
    Set logging file log.txt
     Set logging on 
   To redirect all console output to log.txt

2) Frames and Stacks
   Fr :  To check frames  and move stacked functions.

3) Conditional breakpoints:  
     break WHERE iF COND 

4)  Use a custom command to run every time gdb hit breakpoints
 command  <#>
        use :   # b
                  breakpoint 1 hits at soemfunction 
       #command 1 
          list commands 1per line for to run after breakpoint 1, end with word end 
        > print a 
        >print b
         end  

5) Debugging macros :
        use flags -ggdb3 during compilation 

6) The x command :
     x (for "examine") is used to output regions of memory in various formats. It takes two arguments in a slightly unusual syntax:
        x/ Address
   
 other than these usual command bt,untill,count,watchpoint,source is much effective 

Simple but useful


1)  Share your files and folders residing on your Linux machine with anyone across the web.



Here is the simple way to share files across network on linux , without the need of SMB or NFS .

Open a bash terminal and create an alias as follows:

Next navigate to the directory which you want to share with someone and run  $ python -c "import SimpleHTTPServer;SimpleHTTPServer.test()" command

Your Linux machine will now start serving the whole directory tree on the port number 8000.
And anybody can access all your files within that directory at the following web address – http://:8000/.

Tip:
If you have firewall enabled , you need to open port 8000.

2) Open xwindow apps on remote system:

only local , open a Linux window and type the following:
  • xhost +
  • telnet
  • setenv DISPLAY :0.0
  •      &

Application will open yr local system .


3) Find Out The Top 10 Memory Consuming Process
# ps -auxf | sort -nr -k 4 | head -10
4) Find Out top 10 CPU Consuming Process
# ps -auxf | sort -nr -k 3 | head -10
5) iostat  : average cpu activity
6) pmap -d PID  : memory map of a process
7) copy directory to remote linux 
      scp -r @ :remote .

Thursday, 24 November 2011

Memory Issues : Valgrind and Valkyire

Here come the blog related with Memory management and system management for executable.

Most of the time we are facing issues in c/c++ executable related with the crashes .
the main reason for the crashes are the segmentation fault caused by the address violation by a pointer variable.
Valgrind and Valkyrie is the answer for such situation .

Valgrind:Valgrind is a GPL licensed programming tool for memory debugging, memory leak detection, and profiling

Valgrind is the back end and having command line output which is bit complex to understand.
Valkyrie
Valkyrie is the front end UI tools which ease the understanding .Valyrie is a front-end gui for valgrind v3 and up. It's based on QT, and uses valgrind's xml output to display all the information in a nice tree form. I've started using this as it makes debugging memory problems a heck of a lot easier.

Install Valgrind : use the updated 3.x release in combination of Valgrind 4.x release.

Combine valgrind with valkyrie : Just append the Binary executable with valkyrie keyword with options like
valkyrie --smc-check=none --pointercheck=yes /bin/ls -lF .
one can provide the options using the GUI of Valkyrie options for log files location, format and binary location .

Log files are well defined tree structured . One can save the xml file for ceration scenario. It can be opened and analyzed at any time .

Point to note here : You can get complete code if you run valgrind/valkyrie on Debugged version of binary . Optimized version does not provide the location of error in file .

Valgrind/Valkyrie slow down the process tremendously so one need real patience to get the result .

Enjoy Debugging !!

Saturday, 4 June 2011

Multiple system monitors using single Keyboard and mouse !!! (Synergy)

Software engineers working with different systems. For the Day to day to activities they have a windows laptop/desktop while for coding and development they have a Linux box .
Sometimes multiple keyboard and mouse is simply annoying . Here is a simple solution called Synergy used to connect various system using Client Server network.
Ideally the server should be on Windows system and client on Linux system.

Server Installation :

A well-known open source software for those using multiple monitors.

Synergy :
http://synergy-foss.org/download


It is simple and 5 step process .

1) Launch the synergy for windows (32 bit) . download 1.31 (most stable version)

2) Install in windows ( windows as server)

3) Start the synergy : share this computer keyboard and mouse ….configure


4) Add the system using + sign


5) Screen name should be the computer name in case of server and alias be the IP address. Add another system (Linux) IP as screen name and host name
as an alias.


6) Now most important thing to configure the both monitors under the link and set the left and right position accordingly .
7) Click OK
8) Server is installed .

Client Installation


To install client on a linux system

Steps are
1) Download the source code
2) Untar it using tar zvxf
3) Cd synergy.x.x.
Configure
Make
Make install

4) It will install synergy in your Linux box
5) Just launch synergyc
Default location of synergyc (/usr/local/bin/)

Now just test the client and server and connect it . Both system are using only one Keyboard and mouse .

Sunday, 5 December 2010

Open is not closed but is confused

The open source software’s is still not considered accessible as a part of proprietary software. I as a software developer try to summaries the licensing issues which are faced by a developer s with the use of open source software’s a in the development of a proprietary software trend. Open Source software tends to lack the complete and accessible documentation that retains users. The licensing mechanism of the open source software is ambiguous and Licensing is more critical for developers.
Developers generally feel that the software doesn't quite meet their needs, it lacks a given capability. To resolve the problem, the developers decide to build new functionality. The new, modified solution can be redistributed under the original license and is depending on the license selection. The result of this development is that new software is available for the software developer and organization. The bad news is that some of this software may run the risk of infringing upon patents of which the software authors were perhaps not aware. The numbers of open source licenses create a conundrum in the product development. The process for choosing a license, reviewing code and launching a product without liability concerns becomes more complex as the open source atmosphere expanding day by day.
The open Source Initiative (OSI) maintains a list of software licenses definitions and it certifies the licenses types. Currently it has 50 types of licenses used by open source development. We can divide these as four broader classes of licenses.
1) Academic/University licenses: It is truly open source having no constraints and conditions. Developer can use and redistribute them. Such licenses provide absolute freedom; only constraint here is needed to declare the original licensor's name as an endorsement in marketing efforts. BSD, MIT and Apache foundations of licenses fall in this category
2) Non-Permissive licenses: General public licenses version 2 licenses are restrictive a with respect to proprietary software. Because of its prominence, every project should at least consider a version of the GPL. Any derivatives of the software be released under the same license, and that the source code must be released. The resulting new software must also be free. The indent of such license is to ensure that the free software always remain free in any form. Mozilla public license also is an example of Non Permissive license
3) Permissive GPL license: The Lesser General public licenses (LGPL) much like the GPL, but it allows distribution of works forming certain types of combinations with proprietary, closed-source software. One constraint with such license is the condition with the linking of the open source libraries, these licenses ensure that the open source should dynamically linked to the proprietary software and the changes inside the open source code should be available.
4) Copyright/adaptive licenses: These are the list of open source licenses where the power is in the Initiator and all the contributors. Initial Contributor grants each Recipient a world-wide, royalty-free, non-exclusive copyright license

How to use OSI licenses:
It’s important to understand the effects of selecting the OSI licenses. Each license category has its own particular purpose, whether it's to ensure end-user freedom, prevent commercial use, or preserve a standard code base. One should aware of the fact that the copyrights are not the licenses, for software to reuse or redistribute one need license not the copyright information. In case of open source the copyright is use to keep the license and hence owner has less importance than that of the license. Here is the list of checklist need to perform in case of the OSI license selection
1) Check for permissibility of the open source software and which form developer is going to use the software. If the software falls under first category, the developer is king and having less concern about the legal issues.
2) How: How the software code is being used play a major role of Open software use. The scenario could be different types
->new software may require the Re- license?
->The software is using code base directly or linked?
->Check for the derivative software, some software may include other dependent software as a part.
3) Who: The recognition of the license type is the essence of open source software development. The type may be Apache, BSD, MIT, GPL, LGPL and many more. Each License has own rules and constraints. The agreement statement itself clear the cloud if carefully analyzed
4) Middle ground policy: Use restrictive like GPL for standalone programs, but permissive licenses like BSD for code that will be linked from other code.
5) Combination or derivation: GPL doesn't use the word "combination." It uses the phrase "contains, is derived from or based on “. Sometime it does mean a lot in the legal issues of software development.
6) Binary: The GPL license follow binary mechanism and hence whatever software will developed with GPL for commercial distribution it will fall under GPL, while anything derived from MIT/Academic software remain developer and organization specific.
7) Static Vs Dynamic linking in LGPL: LGPL allow using the open source library either (modified or original) at runtime. The modified open software code needs not to distribute. It is less restrictive in use and hence preferred by the closed software group.




Conclusion: Software License in open source world is a mechanism to communicate the owners and developer about what the software meant for and how it should be developed further. It associate some risks like releasing partially or even fully code along with software. It is recommended that developer should have a clear understating of licensing mechanism to use the open source software, which is one of the most ambiguous and cumbersome tasks.
Open source licenses never meant to restrict the development of software, the need of hour is to understand the importance of open source and follow the correct way to expand the horizons of software.



Refrenses :
http://www.softwarefreedom.org/resources/2008/foss-primer.html
http://www.opensource.org/licenses/apl1.0.php
http://www.catb.org/~esr/Licensing-HOWTO.html#AFL

Tuesday, 11 August 2009

Change Root Password In linux!

The following steps were used to successfully reset the root password of a "Fedora 10" machine. In general, can be applied to any linux machine.


1. GRUBWhile booting, after the initial splash and POST screen of the bios, the control transfers to GRUB. If there is just one linux operating system installed, the GRUB screen is bypassed to the booting screen, in that case just keep on pressing or tapping the ESC Button until you see the GRUB Menu.
2. Edit Choose the OS you want to boot into and press "e" to edit.
3. Edit Find the line that corresponds to kernel, and again press "e". Add the following line to the end of the line.

single init=/bin/bash


Then press enter, and then "b" to boot the OS. After booting you will get a root shell.

4. Mounting the filesystem in readwrite mode: Type in the following command to remount the filesystem in read write mode.

mount -o remount,rw /


Not doing this step might give the following error when running passwd, passwd: Authentication token lock busy.
5. passwd Next just use the passwd command, and give a new root password, Now that's simple.

6. Reboot or init 5




OR from the root shell, you can also edit the /etc/shadow file to remove the password.
OR copy the /etc/shadow /etc/passwd file and use John-The-Ripper software to try cracking the password.