Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created September 26, 2013 09:17
Show Gist options
  • Save yao2030/6711790 to your computer and use it in GitHub Desktop.
Save yao2030/6711790 to your computer and use it in GitHub Desktop.
ex02.sh(new)
#!/usr/bin/sh
pipe=/tmp/out
#trap "rm -rf $pipe" EXIT
#if [[ ! -p $pipe ]]; then
# mkfifo $pipe
#fi
out=1
while true
do
dir=`date +"%u"`
file=`date +"%H"`.log
dirname=`printf "%02d" $dir`
if [[ ! -d "$dirname" && $out -eq "1" ]]; then
mkdir "$dirname"
cd "$dirname"
out=0
fi
if read line <$pipe; then
if [[ ! -e "${file}" ]]; then
touch "${file}"
fi
echo $line >> $file
fi
dirnew=`date +"%u"`
if [[ "$dirnew" -ne "$dir" ]]; then
cd ..
out=1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment