Wednesday, November 13, 2013

How to use scp command without prompting for password

You may need to write a shell script in which you want to copy a file from one server to another. OfCouse you can easily achieve it with SCP command however when you automate the shell script using crontab it will get stuck because of password prompt. To avoid this you want SCP command to work without prompting for password.

Secure Copy (SCP) allows files to be copied to, from, or between different hosts

Let’s assume you want to copy a file from host server (HOST) to destination server (DEST).

1. On HOST server run below command

$ ssh-keygen -t rsa

First it will prompt for "Enter file in which to save the key" just keep it blank by pressing enter. Then it will prompt for passphrase, again keep it blank by pressing enter. It will generate a public key (id_rsa.pub) and a private key (id_rsa) in the folder <your_home_dir>/.ssh

Output -

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/.ssh/id_rsa.
Your public key has been saved in /home/.ssh/id_rsa.pub.
The key fingerprint is:
1a:7b:3b:d7:5c:f0:6d:f1:01:75:0f:b1:71:6a:15:be user@HOST

2. Share the public key (id_rsa.pub) with DEST server

Copy the file id_rsa.pub from HOST to <your_home_dir>/.ssh folder of DEST. You can use scp or ftp anyway you are comfortable with.

3. Copy the contents of id_rsa.pub to <your_home_dir>/.ssh/authorized_keys2 in DEST server

Below command will append the content of id_rsa.pub to authorized_keys2. Note - you may even copy to authorized_keys whichever file exits on <your_home_dir>/.ssh in DEST server

$ cat id_rsa.pub >> authorized_keys2

Now if you use SCP command to transfer a file from HOST to DEST it won’t prompt for password. I hope it helped you.

Java program to play an audio sound

These are the following ways in which you play a sound in Java.

Toolkit - If you just want a beep or quick alert you can use beep() finction of class java.awt.Toolkit. It Emits an audio beep.
AudioClip - The AudioClip interface is a simple abstraction for playing a sound clip.
Clip - The Java Sound API provides functionality for the capture, processing, and playback of sampled audio data & the sequencing and synthesis of MIDI data.
MIDI Sequences - The javax.sound.midi package provides an interfaces and classes for I/O, sequencing, and synthesis of MIDI (Musical Instrument Digital Interface) data.

Please see the sample code of each type


Wednesday, November 6, 2013

Example using Java.awt.Robot class

Java.awt.Robot class is used to take the control of mouse and keyboard. In this example we will open a notepad and type a message. Please see the self explanatory code below.

Tuesday, November 5, 2013

Top 5 Popular jQuery Plugins


Author Bio: Danica loves technology and she constantly advises people on the best web hosting platforms for using jQuery as well as a host of other coding libraries. She is an expert at using PHP and hopes to start her own development company in the future.

jQuery is one of the most popular libraries available to webmasters and developers, and a big reason for that is the large number of high quality plugins that are available. These help novice webmasters and developers to create professional looking websites filled with different features, while those with experience can use jQuery to add the finishing touches to what is already an exceptional platform.

That said, one of the worst things for a developer to do online is to overuse plugins, widgets, and various other things that are available in order to enhance the user experience of a website. With that in mind, we have looked at five of the best and most popular jQuery plugins you could use on your website.

Cycle 2

If static images are a big part of your website, then the Cycle 2 jQuery plugin is a great way to take your imagery to the next level and create exciting slideshows on your web pages. What makes this plugin a winner is that it is so easy to use; all you need to do is include the plugin and mark-up to your code, and everything else is done for you. Although this is the perfect plugin for new webmasters or bloggers, it is also loved by those with great knowledge of web development owing to its ability to work within responsive design themes.

FitVids

While many people fret about how having video content on their website will slow down loading times, some struggle to even get video onto their pages at all. Those who want to make video a feature of their site should consider using FitVids, especially if they are embedding video content that is already featured on sites like YouTube.

Even though modern HTML5 coding makes it easy to embed your own videos from your disk or device, it is still worth using a plugin like FitVids so you can be flexible with the video content on your site.