shubham
shubham

Reputation: 21

getting "grep: write error: pipe broken" when command executed through application installation

Below is the command which is executed when I install the application(this line written in one of the script of our application). PASS=strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 10 | tr -d '\n'

every time I get the error "grep: write error: pipe broken".

here are few points to be noted

  1. When I install the application on RHEL 7.X. It runs without an issue.
  2. When I run the command directory on RHEL 8.X. it doesn't give an error.
  3. It throws an error only when installing the application on RHEL 8.x.

Also, I have tried few other ways to generate alphanumaric character like:

  1. X=strings /dev/urandom | grep -o -m15 '[[:alnum:]]' PASS=echo "$X" | head -n 10 | tr -d '\n'

  2. PASS=strings /dev/urandom | tr -dc A-Za-z0-9 | head -c10

  3. PASS=cat /dev/urandom | tr -dc A-Za-z0-9 | head -c10

  4. X=strings /dev/urandom | head -n 100 PASS=echo "X" | grep -o '[[:alnum:]]' | head -n 10 | tr -d '\n'

  5. PASS=< /dev/urandom tr -dc '[[:alnum:]]' | head -c10

None of this worked on RHEL 8.X while installing application. However all this command works fine when executing directly on terminal.

Upvotes: 1

Views: 2115

Answers (1)

Armali
Armali

Reputation: 19375

The command

PASS=`strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 10 | tr -d '\n'`

does not work due to a bug in strings. head exits after having read 10 lines; grep detects that the other end of its output pipe has been closed, issues grep: write error: Broken pipe and also exits; strings ignores that the other end of its output pipe has been closed and blindly continues endlessly.

The commands 3. and 5. which don't use strings correctly generate a 10 character password, although 3. also issues write error: Broken pipe.

Upvotes: 1

Related Questions