‏הצגת רשומות עם תוויות Bash. הצג את כל הרשומות
‏הצגת רשומות עם תוויות Bash. הצג את כל הרשומות

יום רביעי, 27 בנובמבר 2013

Tail, grep, and stdio buffering

I was engaged in some troubleshooting once and needed to follow a log and specifically capture some string as soon as it appears in the log.
I have started my way, believing that using tail logfile | grep string will suffice, but after a few minutes of struggling to understand a certain delay between the actual server responses and the output on my screen I have realised there is some buffer at work here.
some google query afterwards I have came to acknowledge a known buffer that exists specifically in linux distributions (wasn’t able to replicate in solaris) which in order to override needs the flag --line-buffered added to grep.
so now that I run
 tail logfile | grep --line-buffered string
I expect to immediately (as possible) see the requested string shown on the stdio as soon as it is being written on the logfile.

יום שישי, 27 בינואר 2012

Bash script to copy changes from SVN to a different location

This was originally made by request from a developer from my office.
#!/bin/bash
NEWDIR="/home/usern/svn-script"
for file in $(svn status | tr -s ' ' ' ' | cut -d" " -f2)
do
declare -i DIRLEVEL=$(grep -o "/" $file| wc -l)
DIRLEVEL=$( echo "$DIRLEVEL - 1" |bc )
SRCPATH=$(echo $file | cut -d"/" -f1-"$DIRLEVEL" )
mkdir -p $NEWDIR/$SRCPATH
cp -v $file $NEWDIR/$SRCPATH
done
later to be updated and improved by Lev to include better method to parse the path and scenarios where files should be ignored.
#!/bin/bash

NEWDIR="${1:-$HOME/svn-script}"

mkdir -p "${NEWDIR}"
if [ $? -ne 0 ]then
echo "Could not create ${NEWDIR}"
exit 1
fi

# check if running from subversion dir:
if [ ! -d .svn ]then
echo "This is not a working copy directory!"
exit 1
fi

for FILE in $(svn status | awk '$1 ~ /[AMR]/ { print $2 }')do
if [ -d ${FILE} ]then