Skip to content

Instantly share code, notes, and snippets.

@tfoldi
Created May 18, 2010 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfoldi/404869 to your computer and use it in GitHub Desktop.
Save tfoldi/404869 to your computer and use it in GitHub Desktop.
smbclient based sync between windows and unix
#!/usr/bin/ruby
#
# Foldi Tamas <tfoldi@xsi.hu>, BSDL
require "yaml"
# read configuration
@yxlan_dir = File.dirname($0) + "/../"
@conf = YAML::load_file( @yxlan_dir + 'etc/yxlon.conf' )
@filename = @yxlan_dir + "log/yxlon_cron.log"
def logger(s)
f = File.open(@filename,'a')
f.puts "#{get_formatted_time} #{s}"
f.close
end
def get_formatted_time
t = Time.now
t.strftime("%Y.%m.%d. %H:%M:%S")
end
@conf["gepek"].each do |gep|
# create timestamp file if it does not exist
unless File.exist?( "#{@yxlan_dir}var/#{gep['nev']}.tar" )
system "touch -t 8001010000 #{@yxlan_dir}var/#{gep['nev']}.tar"
end
# get new files
logger "Getting files from \\\\#{gep['ip']}\\#{gep['konyvtar']}"
system "smbclient '\\\\#{gep['ip']}\\#{gep['konyvtar']}' '#{gep['pass'] || ''}' -U #{gep['user']} -TcN #{@yxlan_dir}var/#{gep['nev']}.tar #{@yxlan_dir}var/#{gep['nev']}.tar\n"
# extracting files
logger "Extracting file to #{@conf['samba_dir']}"
system "tar -C #{@conf['samba_dir']}/#{gep['nev']} -xvf #{@yxlan_dir}var/#{gep['nev']}.tar"
end
yxlon_dir: /opt/yxlon
samba_dir: /samba/yxlon
gepek:
- nev: RA1HOST
ip: 10.124.1.10
konyvtar: ExportStatistics
user: xxx
pass: xxx
- nev: RA3HOST
ip: 10.124.3.10
konyvtar: ExportStatistics
user: xxx
pass: xxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment