开发者

How can I list files for an init.d script without ruby

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 easil开发者_开发技巧y 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


This should do the job:

JARS=`ls $HOME/lib/*.jar | tr '\n' ':'`


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜