2018/05/26

inotifywait example

edit: modified parameter "-n 1" to the "head" command

for this example I'm assuming text files:
to avoid confusions long lines are splitted with \


#!/bin/bash

if [ $# -ne 2 ]
    then
    echo "$0 <src dir> <dst dir>"
    exit
fi

clear

inotifywait $1 -qmre CLOSE_WRITE \
--format='%f' | while read WHICHONE ; do  

   if [ $? != 0 ]; then exit; fi;
   LINESELECTED=$(head -n 1 $WHICHONE | \
grep CONDITION)

if[ $LINESELECTED -eq 1 ] then
   cp $1/$WHICHONE $2
fi


done

2018/05/17

bash scripts for directories based on date

#!/bin/bash

#Path YYYYMMDD
ANO=$(date +%Y)
MES=$(date +%m)
DIA=$(date +%d)
FULL=$ANO$MES$DIA

if [ "$FULL" == "" ]; then
    exit 1
fi

#generar directorio destino
DIRDESTINO=/picadora/eimpresa/fotos/$ANO$MES$DIA
mkdir -p $DIRDESTINO
chmod 777 $DIRDESTINO

mkdir -p $DIRDESTINO/tapa
chmod 777 $DIRDESTINO/tapa

# generar link simbolico a HOY
cd /picadora/eimpresa/fotos
rm hoy
ln -s $DIRDESTINO hoy
cd $DIRDESTINO

# lo que siga despues

2018/05/04

phpunit script

assuming theres a test directory inside a project where the source files are held:

#!/bin/bash

if [ $# -ne 2 ]
    then
    echo "testphp <test dir> <src dir>"
    echo "example: $ testphp test ."
    exit
fi

clear

inotifywait $2 -qmre CLOSE_WRITE --format='%f' | while read CUAL ; do  
   if [ $? != 0 ]; then exit; fi;
   clear
   phpunit.phar --log-junit /tmp/ultimo.txt --color -v $1
done