ruby+sourceinsight+gmake搭建unix开发环境

最近做了个小程序,从网上抓取一些数据,并进行处理,

流程大致是这样的,

java写个spider,通过hibernate写入postgresql,maven运行,并且把maven放在crond。在网上出现需要的数据的大致时间点自动运行;

用shell 和psql 还有sed命令从数据库中取出网上抓来的数据,放入data.ini文件;

c++ stl写一个小程序咀嚼data.ini,输出到stdout;

再用sed命令和psql写回数据库。

搞着么复杂是因为综合了以前很多小程序,完成此次流程。

其中那个c++stl程序原是在vc2005下的,把它移植到freebsd下。在sourceinsight编辑,调用脚本语言发送到服务器,gmake后读取反馈信息(编译错误等),定位到行。

开始装了perl,搞了半天,一个小小的ssh登录搞不定,什么Expect不支持等。

后来用了ruby,挺直接的   ,make_remote.rb:

require 'net/ssh'
require 'net/sftp'
require 'find'

local_path = "#{ARGV[1]}"
puts "local path:#{local_path}"
remote_repo =  "/usr/home/zh/project"
remote_path = "#{remote_repo}/#{ARGV[0]}"
puts "remote path:#{remote_path}"
file_perm = 0600
dir_perm = 0700


def do_cmd( session ,cmd)
  session.open_channel do |channel|
     channel.on_data do |ch, data|
      puts "#{data}"
    end
    channel.exec "#{cmd}",true
  end
end


puts 'Connecting to remote server......'

Net::SSH.start('218.193.237.11', 'zh', '') do |ssh|

ssh.sftp.connect do |sftp|
 puts 'Checking for files which need updating'
 Find.find(local_path) do |file|
   next if File.stat(file).directory?
   local_file = "#{file}"
   remote_file = remote_path + local_file.sub(local_path, '')

   begin
     remote_dir = File.dirname(remote_file)
     sftp.stat(remote_dir)
   rescue Net::SFTP::Operations::StatusException => e
     raise unless e.code == 2
     sftp.mkdir(remote_dir, :permissions => dir_perm)
   end

   begin
     rstat = sftp.stat(remote_file)
   rescue Net::SFTP::Operations::StatusException => e
     raise unless e.code == 2
      puts "Copying #{local_file} to #{remote_file}"
    sftp.put_file(local_file, remote_file)
     sftp.setstat(remote_file, :permissions => file_perm)
     next
   end

   if File.stat(local_file).mtime > Time.at(rstat.mtime)
     puts "Copying #{local_file} to #{remote_file}"
     sftp.put_file(local_file, remote_file)
   end
 end
end

puts 'making project......'

shell = ssh.shell.sync
out=shell.send_command( "cd #{remote_path}&&gmake #{ARGV[2]}")
puts out.stderr

if ARGV[2]=='run'
 puts out.stdout
end

puts 'Disconnecting from remote server......'
end

(好像密码都不用填,会去读取putty配置?)

 

总结一下使用的东西:sourceinsight、shell、c++、java、maven2、postgres、ruby、freebsd、boost serialization

现在这个东西完全自动了,抓取web数据,自动计算,到时看结果就行了

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值