# old script not working now



## free-and-bsd (May 26, 2016)

Hi people,

I used to use this script to generate random passwords:

```
strings /dev/urandom | grep -o '[[:print:]]' | head -n 30 | tr -d '\n'; echo
```
Well now it doesn't generate anything, just hangs. I'm in bash, not sh. Just wonder what has changed and whether it's due to my using CURRENT.


----------



## kpa (May 26, 2016)

It's probably the binary file detection in grep(1) kicking in:


```
--binary-files=TYPE
              If the first few bytes of a file indicate that the file contains
              binary  data, assume that the file is of type TYPE.  By default,
              TYPE is binary, and grep normally outputs either a one-line mes‐
              sage  saying  that a binary file matches, or no message if there
              is no match.  If TYPE is  without-match,  grep  assumes  that  a
              binary file does not match; this is equivalent to the -I option.
              If TYPE is text, grep processes a binary  file  as  if  it  were
              text;  this  is  equivalent  to  the  -a  option.  Warning: grep
              --binary-files=text might output binary garbage, which can  have
              nasty side effects if the output is a terminal and if the termi‐
              nal driver interprets some of it as commands.
```

I would do it this way:

`dd if=/dev/urandom count=1 2>/dev/null | grep --binary-files=text -o '[[:print:]]' | head -n 30 | tr -d '\n'; echo`


----------



## free-and-bsd (May 26, 2016)

Thank you, that works!

However, it's not just grep, the same happens with bare `strings /dev/urandom` command -- no output at all, just wait. Only `cat /dev/urandom` gives off symbols.


----------



## kpa (May 26, 2016)

I just noticed that you might get some non-ASCII characters as well with my solution depending on your locale and that's not good for passwords. This should work better:

`dd if=/dev/urandom count=1 2>/dev/null | env LC_ALL=C grep --binary-files=text -o '[[:print:]]' | head -n 30 | tr -d '\n'; echo`


----------



## usdmatt (May 26, 2016)

On one of my 10.x systems I get a GNU page if I run man strings, with references to binutils and FSF Inc. On 11 I get a completely different man page which suggests the GNU strings has been replaced (probably as part of the work to remove GNU code from FreeBSD). That might have something to do with it...

Edit: Interestingly enough it seems to produce output if you use the -a option, although it doesn't make a huge amount of sense to me based on the description of that option in the man page.

```
# strings -a /dev/urandom | head -n 1
hC,05|
```


----------



## kpa (May 26, 2016)

It's possible that the results of the BSD ToolChain project have finally hit CURRENT. Use of strings(1) for this purpose is however wrong, the tool makes some assumptions about the input files because it's designed for looking inside ELF object and executable files.


----------



## free-and-bsd (May 26, 2016)

usdmatt said:


> On one of my 10.x systems I get a GNU page if I run man strings, with references to binutils and FSF Inc. On 11 I get a completely different man page which suggests the GNU strings has been replaced (probably as part of the work to remove GNU code from FreeBSD). That might have something to do with it...
> 
> Edit: Interestingly enough it seems to produce output if you use the -a option, although it doesn't make a huge amount of sense to me based on the description of that option in the man page.
> 
> ...


A! There you have it. The last time I used this one successfully was under 10.x. And yes, the BSDToolChain is in CURRENT.


----------

