#!/usr/bin/ruby -w ## truncat - truncate file by tailing it into itself as in bash ## file="/var/log/mysql.log"; tail $file > $file ## name is an abbreviation and a nod to Cory Doctorow's story of that title ## a sequel of sorts to his novel _Down and Out in the Magic Kingdom_ require 'ftools' ## display usage help def usage() p 'truncat: Truncate file by tailing it to itself. Takes one argument, so far.' exit() end ## check arg count and type a little def check_args() ## if argcount is not one, quit if ARGV.size != 1 p "#{ARGV.size} is not one." usage() end ## if arg is not a file, quit if ! File::exists?(ARGV[0]) p "#{ARGV[0]} is not a File." usage() end ## if we cannot write to arg, quit if ! File::writeable?(ARGV[0]) p "#{ARGV[0]} not writable as `id` right now." usage end ## still here? set arg @victim = ARGV[0] end def trunc(victim) `tail victim > @victim` end check_args() trunc(@victim) exit