views:

54

answers:

2

I need to convert a init.d script that uses ruby to not use ruby. I can use perl or python or something else, but I can't use ruby. My main problem is figuring out how to dynamically get the list of *.jar files in a directory and separate them with ':'. The rest I could easily do with a bash script.

Here is the Ruby code I'm working with:

#!/usr/local/bin/ruby

require 'fileutils'

HOME = '/usr/local/myproject'
JAVA_HOME = '/usr/java/jdk'
JARS = Dir.glob(File.join(HOME, 'lib', '*.jar')).join(':')
PID_FILE = '/var/run/myproject.pid'
OUT_FILE = File.join(HOME, "stdout")
ERR_FILE = File.join(HOME, "stderr")

case ARGV.first
when 'start'
  exec "/usr/local/bin/jsvc -home #{JAVA_HOME} -cp #{JARS} -pidfile #{PID_FILE} -DHOME=#{HOME} -user me -outfile #{OUT_FILE} -errfile #{ERR_FILE} mypackage.MyProject"
when 'stop'
  exec "/usr/local/bin/jsvc -home #{JAVA_HOME} -cp #{JARS} -pidfile #{PID_FILE} -stop mypackage.MyProject"
end
+4  A: 

This should do the job:

JARS=`ls $HOME/lib/*.jar | tr '\n' ':'`
pejuko
For maximum portability, I think you need `ls -1 ...` to force output as one file per line.
Andrew Walker
+1  A: 

My main problem is figuring out how to dynamically get the list of *.jar files in a directory and separate them with ':'

For Perl solution then take a look at the glob function which returns a list of files.

my $HOME = '/usr/local/myproject';

my $JARS = join ':', glob( $HOME . '/lib/*.jar' );

/I3az/

draegtun