Is it possible to safely ignore the aforementioned error message? Or is it possible to remove the null byte? I tried removing it with tr
but I still get the same error message.
this is my script:
#!/bin/bash
monitordir="/home/user/Monitor/"
tempdir="/home/user/tmp/"
logfile="/home/user/notifyme"
inotifywait -m -r -e create ${monitordir} |
while read newfile; do
echo "$(date +'%m-%d-%Y %r') ${newfile}" >> ${logfile};
basefile=$(echo ${newfile} | cut -d" " -f1,3 --output-delimiter="" | tr -d '\n');
cp -u ${basefile} ${tempdir};
done
when I run inotify-create.sh
and I create a new file in "monitordir"
I get:
[@bash]$ ./inotify-create.sh
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
./inotify-create.sh: line 9: warning: command substitution: ignored null byte in input
echo ... | tr -d '\n'
, why not useecho -n ...
?--output-delimiter=""
part of yourcut
invocation that's generating the null bytes, are you able to use a different delimiter? And besides to rid null bytes you needtr -d '\0'
and nottr -d '\n'
cut
toawk '{ print $1$2$3 }'
, but I don't know what your input looks like. You also don't need to end every statement with;
. You only need to do that if two statements are written on the same line./home/user/Monitor/ CREATE newfile
with a newline at the end. What aboutbasefile=$(echo ${newfile} | gawk -F " " '{print $1$3}')
? Any reason not to use gawk (ie speed)?read
should bewhile read -r dir _ file
andbasefile
then becomes${dir}${file}