Can I safely ignore: "warning: command substitution: ignored null byte in input"?
As for your exact question:
Can I safely ignore: “warning: … ignored null byte … ”?
The answer is yes, since you are creating the null byte with your own code.
But the real question is: Why do you need a "null byte"?
The inotifywait
command will produce an output in the form of:
$dir ACTION $filename
Which, for your input, looks like this (for file hello4):
/home/user/Monitor/ CREATE hello4
The command cut will print fields 1 and 3, and using a null delimiter in --output-delimiter=""
will produce an output with an embedded null, something like:
$'/home/user/Monitor/\0hello4\n'
That is not what you need, because of the added null.
The solution turns out to be very simple.
Since you are using the command read
already, do this:
#!/bin/bash
monitordir="/home/user/Monitor/"
tempdir="/home/user/tmp/"
logfile="/home/user/notifyme"
inotifywait -m -r -e create ${monitordir} |
while read dir action basefile; do
cp -u "${dir}${basefile}" "${tempdir}";
done
Use the default value of IFS to split on whitespace the input and just use the directory and filename to copy.
Related videos on Youtube
aperture
Updated on September 18, 2022Comments
-
aperture almost 2 years
I'm using Angular to post some data to a Django endpoint with:
$http({ method: 'POST', url: '/api/projects/166/interval_sort/', data: JSON.stringify({ids: [251,250,249,235,233,234]}) })
And in my view method, request.POST is an empty
<QueryDict: {}>
def ProjectIntervalSort(request, pk): logger.debug("SORTABLE DATA: "+str(request.POST)) return HttpResponse(status=204)
Chrome's network inspector shows my JSON object being sent, but I don't seem to be able to access it from the Django side. Am I not formatting the data correctly or missing something in my view method? Thanks.
-
Pankaj Goyal over 7 yearsNot an answer, but instead of using
echo ... | tr -d '\n'
, why not useecho -n ...
? -
Mathias Begert over 7 yearsit's the
--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'
-
Kusalananda over 7 yearsYou could possibly change the
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. -
jes516 over 7 yearsi need --output-delimiter="" because otherwise i get a space in between the directory and filename. The variable $newfile outputs
/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)? -
Mathias Begert over 7 years@jes516, in that case your
read
should bewhile read -r dir _ file
andbasefile
then becomes${dir}${file}
-
-
aperture over 8 yearsAh, perfect. SO will let me accept this in like 10 minutes. Thanks.
-
jes516 over 7 yearsthis is even better. now the man page makes sense
watched_filename EVENT_NAMES event_filename
akadir action file
ty