Jump to content
Sign in to follow this  
_vern_

GREP behavior changed?

4 posts in this topic Last Reply

Recommended Posts

Hello all,

I'm really just posting this because I want to see if anyone else has experienced this behavior with grep in unraid. I don't think this is an issue with unraid per se. I have a bash shell script that I have been running for several years without issue. The day after I upgraded to 6.7 the script broke and I had no idea why. After a couple of hours of trouble shooting I discovered the line below, which the output is supposed to be saved to a variable, wasn't grabbing anything. Note: this is not the full line of code...just the part the demonstrates the behavior.

virsh domblklist "domain" --details | grep ^file

If you run this line at the command line in unraid, assuming you are running virtual machines, and replace "domain" with the name of a VM, it should return a line of information on the VM...or so it used to. When I run this now it returns nothing, which caused the variables to never get populated which caused the script to fail. If I drop the caret (regex), it returns what is expected. It appears the grep version changed in 6.7, but I can't find any information concerning any changes to grep that would have caused this behavior. So, I'm curious if anyone else has run across this behavior and maybe more importantly, educate me. It's just one of those little mysteries that causes me to slowly lose my sanity! Thanx!

Edited by _vern_

Share this post


Link to post

I tried the following simple tests and grep works as expected:

root@Server:~# echo file test | grep ^file
file test
root@Server:~# echo test file | grep ^file
root@Server:~# cat file.txt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>
root@Server:~# cat file.txt | grep ^it
it under the terms of the GNU General Public License as published by
root@Server:~# cat file.txt | grep ^the
the Free Software Foundation, either version 3 of the License, or
root@Server:~#

 

Edited by JoeUnraidUser
Added file cat tests.

Share this post


Link to post

Thank you...I have figured out what has changed. The virsh domblklist --details command output has changed...the line of data now begins with a space so the pattern "^file" no longer matches it. Mystery solved. Thank you for the reply!

Share this post


Link to post

It just had to be something like that. Changing the behaviour of grep itself would result in untold chaos. Glad you sorted it. Sanity restored!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this