Download sequence of files using Curl

In day to day life we used to download useful stuff from world wide web, sometime requirement to download sequence of files, one way is to do it manually by clicking individual links or automate the download using Curl.

Showing you that next, how we can do it.

grab Curl from : http://curl.haxx.se/download.html

Curl has the ability to set sequences (including with leading zeroes, and alphanumeric sequences) as part of the download command which makes it a lot easier. This is all covered in the man page so I suggest reading it for a complete understanding of the options available.
Continue reading “Download sequence of files using Curl”

UNIX: How to Automate SSH Login

Yesterday, I was working on some shell script piece for my project and I came across a situation where I have to copy some files from one server to another using ‘scp’ command and also some time have to execute some command on other server.  One requirement was we don’t need to pass the password of functional id inside the script.

User should be able to login to other server without password using command  “ssh -l username remotehost”.

For this I used SSH public key based authentication as below:-

Continue reading “UNIX: How to Automate SSH Login”

Count lines of multiple similar files in unix

In continuation to my earlier post regarding concatenation similar files into one. I am writing this post to demonstrate counting lines of similar kind of files in a given directory and sub-directory.

Below command will find all the logs with given name pattern inside the directory including sub directories and then WC will count it’s lines and display on screen in total.

Continue reading “Count lines of multiple similar files in unix”

Java Return Value to Unix Shell Script

Today I faced a situation where I need to verify something though Java class in database . My problem was I have to do this inside unix shell script. I created the below solution to achieve that, I am posting here sample working code:

JAVA CLASS

public class Sample
{

public static void main(String args[])
{
//Do the complete logic and print the result using system out
System.out.println(“Sample Testing”);    
}
}

Shell Script

Continue reading “Java Return Value to Unix Shell Script”

How to send an email from UNIX using mailx.


#!/bin/sh
#
# Purpose: Demonstrate how to send an email from UNIX using mailx.
############################################################

# Example 1 – Simple:
echo “This is the body.”| mailx -s “mailx Test1” sample@sample.com

# Example 2 – Using Variables:
SUBJECT=”mailx Test2″
EMAIL_ADDRESS=”sample@sample.com
BODY=”This is the body of the message.”

echo “$BODY” | mailx -s “$SUBJECT” “$EMAIL_ADDRESS”

Continue reading “How to send an email from UNIX using mailx.”

Delete .svn directories recursively

I am here showing an example of a unix command, which recursively deletes subversion .svn folders. Subversion is a widely used open-source revision control application. Every copy of source code received from subversion repository has .svn folders, which store metadata. However, if you want to use or distribute source code, these .svn folder are often not necessary.

To remove this we can follow the following steps:

We use find command to find all .svn folders beginning from current directory.

$ find . -type d -name .svn ./.svn ./sourceA/.svn ./sourceB/.svn ./sourceB/module/.svn ./sourceC/.svn

Now pass this to RM command using grave accent quotes (key (`) to left of ‘1’)

$ rm -rf `find . -type d -name .svn`

If you need to remove the .svn very frequently then simply save this command inside a script and execute that whenever is required.

Hope this helps 🙂