Created
October 18, 2013 18:46
-
-
Save niklas/7046177 to your computer and use it in GitHub Desktop.
script to generate symlinks to a ramdisk (good for logs) TODO: * repair symlink targets after reboot
* run automatically after chdir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pathname' | |
# global setup | |
ramdisk = Pathname.new( Dir.home(ENV['USER']) ).join('tmp') | |
if File.read('/etc/mtab').lines.grep(%r~ #{ramdisk} ~).empty? | |
system "mount", ramdisk.to_s | |
end | |
arg = ARGV.shift || raise("must give directory to mirror") | |
arg = Pathname.new(arg).expand_path | |
arg.file? && raise("is a file: #{arg}") | |
logs = ramdisk.join(arg.basename) | |
if arg.directory? | |
Pathname.glob(arg.join('*.log')).each do |old| | |
system "rm", "-i", old.to_s | |
end | |
arg.children.empty? || raise("still contains files: #{arg}\n#{arg.children.join(' ')}") | |
system "rmdir", arg.to_s | |
end | |
name = arg.dirname.basename | |
log = logs.join name | |
system "mkdir", '-p', log.to_s | |
system "ln", "-s", log.to_s, arg.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment