tests-always-included / wick

Bash-only IT automation, machine provisioning
Other
69 stars 12 forks source link

Skipping chkconfig if it is not there. #95

Closed quantumew closed 8 years ago

quantumew commented 8 years ago

Ran into a case where the chkconfig line was not there in our consul init file and I wanted to set an override for Dolphin.

fidian commented 8 years ago

I would rather not run grep twice. How about we just consume the error?

grep '^# chkconfig:' "b" || : | head -n 1 >> "$dest"
quantumew commented 8 years ago

Didn't work exactly the way you had it. I had to keep the if there so we weren't echoing an extra blank line into the override file. Also had a brain fart and put the wrong switch the first time. 7c9f488a479135a87a8132a2437cbe74edbef1c9 6a56aa4f9fa351896314a82a3fc3d40896f9dfc0

fidian commented 8 years ago

screenshot from 2016-10-05 16-55-45

I had to wrap the code in parenthesis, but otherwise the code seems to work very well. I later played a bit and you can eliminate the parenthesis (and thus eliminate the subshell) if you use braces like so:

{
    grep '^# chkconfig:' "$file" || :
} | head -n 1 > "$dest"

If this solution does not work for you, let me know.

quantumew commented 8 years ago

Thanks, wasn't aware that was possible. I was also worried the newline that gets output to the override file on a miss was a problem but it is not. 0d7543e7af4f3ccd9c74a8b79fd3bc72badbc206

fidian commented 8 years ago

I didn't ever see a newline on a miss. The : command doesn't output a newline.

fidian commented 8 years ago

Squashed and merged! Thanks for the help!