Shell script to encrypt the xls file using executable jar in Linux SUSE 11.4

Dear Experts,

I am an ERP consultant and would like to learn shell script. We are working on Linux SUSE 11.4 and I am very new to shell scripting. We can manually encrypt an excel file using "executable jar" through command prompt by placing the jar file & the file to be encrypted on a physical path and the same need to achieved using shell script in Linux which will be later called by middle ware tool to encrypt the file automatically instead of manual. I have the server access, can you please guide me to achieve this as early as possible.

The command used in cmd is

java �jar  <<name of jar file>>.jar  <<full path of the file>>

Please help me to achieve this.

Thanks,
Nithin.

Assuming that you're using a POSIX-conforming shell (such as ash , bash , date , ksh , or zsh ), you just need to put your commands in a file with a little bit of shell script boilerplate, parameterize the part(s) of the command that need to be supplied on the command-line when you invoke your script, add some error checking to be sure that the needed command-line arguments are present when your script is invoked, make the script executable, and put it in a directory where the people who need to execute your script will be able to find it.

I prefer the Korn shell, so I will use it for this example, but the code supplied here will work with any POSIX-conforming shell if there is some reason why you don't like the Korn shell. First place the following text in a file named whatever name you want to use when you invoke this script. (I'll assume that you named it makejar in the following directions.) Note that you must use an editor that uses the <newline> character as the line terminator (not the DOS <carriage-return><newline> character pair) when you create this file:

#!/bin/ksh
# Save last component of pathname used to invoke this script for use in diagnostic messages.
IAm=${0##*/}

# Verify that we were invoked with two operands.
if [ $# -ne 2 ]
then	# Print usage message to stderr and exit.
	printf 'Usage: %s name_of_jar_file file_pathname\n' "$IAm" >&2
	exit 1
fi

# Allow 1st operand to be specified with or without ".jar".
jar_file=${1%.jar}.jar
path=$2

# Run the desired command...
java -jar  "$jar_file"  "$path"

Then make the file executable:

chmod +x makejar

Assuming that this command is for your personal use, move it into your bin directory (creating it if it doesn't already exist):

mkdir -p $HOME/bin
mv makejar $HOME/bin

Then, assuming that $HOME/bin is in your PATH environment variable, you can execute your script just by typing its name and the parameters you want to pass to it just as you would with any other command you give to your shell:

makejar myjar /path/to/myjar

or:

makejar myjar.jar /path/to/myjar