import os
import random

DIR       = '/usr/bin'
LIMIT     = 300

FILE_LIST = "file_list.txt"
FILE_SCP  = "scp_list.sh"

files = [x.strip() for x in os.popen("find %s -type f -and -perm 555"%(DIR)).readlines()][:LIMIT]
random.shuffle(files)

# Write file list
print "Writing", FILE_LIST, '..'
open (FILE_LIST, 'w+').write ('\n'.join(files))

# Write the scp script
print "Writing", FILE_SCP, '..'
command = '''#!/bin/sh

if test $# = 0; then
  echo "ERROR: Host:Directory required"
  exit
fi

scp %s $1
''' % (' '.join(['"%s"'%(x) for x in files]))
open (FILE_SCP, 'w+').write (command)

# File sizes
total    = 0
biggest  = 0
smallest = 2<<31

for f in files:
    size = os.stat(f)[6]
    total += size
    biggest  = max(biggest, size)
    smallest = min(smallest, size)

average = total / len(files)
print "Average size:       % 9d bytes" %(average)
print "Smallest file size: % 9d bytes" %(smallest)
print "Biggest file size:  % 9d bytes" %(biggest)

