Skip to content

Instantly share code, notes, and snippets.

@andrewhavck
Created January 14, 2010 14:53
Show Gist options
  • Save andrewhavck/277219 to your computer and use it in GitHub Desktop.
Save andrewhavck/277219 to your computer and use it in GitHub Desktop.
Auto log script for senior project website
#!/usr/bin/env ruby
require 'net/ssh'
require 'net/sftp'
require 'ruby-debug'
name = 'andrew'
remote_path = 'sp/website/' + name +'.html'
if ARGV.empty?
puts "Usage: [E-ID]... [PASSWORD]... [LOG]...\n\n"
exit
else
Net::SSH.start('home.cs.siue.edu', ARGV.fetch(0), :password => ARGV.fetch(1)) do |ssh|
ssh.sftp.connect do |sftp|
f2 = sftp.file.open(remote_path + "2", "w")
f = sftp.file.open(remote_path, "r")
while !((line = f.readline) =~ /<!-- done -->/)
f2.puts line
if line =~ /<!-- auto logs -->/
f2.puts "<span class=\"log\">" + ARGV.fetch(2) + "</span>\n"
f2.puts "<br>\n"
f2.puts "<span class=\"author\">written by " + name + " on " + Time.now.month.to_s + "/" + Time.now.day.to_s + "/" + Time.now.year.to_s + "</span>\n"
f2.puts "<br>\n<br>\n<br>\n"
end
end
f2.puts "<!-- done -->"
f.close
f2.close
sftp.remove(remote_path).wait
sftp.rename(remote_path + "2", remote_path).wait
sftp.remove(remote_path + "2").wait
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment