#!/usr/bin/env bash # # #Write characters specified in argv[1] to file argv[2] unless file exists #Must be run as root #Length determined by $RANDOM % 94 # function helper(){ echo "Syntax: $0 [ r | n ] output-file $0 c char-to-fill-with output-file Where r = 'random chars' and n = 'nul values' If using 'c', only one character may be specified Output must not already exist Command must be run as root" exit } if (( $# < 2 )) || [ -f ${!#} ] || [ "$(whoami)" != "root" ]; then helper fi LEN=`echo $1|wc -c` SIZE=$(($RANDOM % 94)) if [ "$1" == "r" ]; then dd if=/dev/urandom of=$2 count=$SIZE elif [ "$1" == "n" ]; then dd if=/dev/zero of=$2 count=$SIZE elif [ "$LEN" == "2" ] && (( $# == 3 )); then # One block = 512 chars for (( a=0;a<$SIZE*512;a++ )); do echo "$2" >> $3 done else helper fi