2

I wrote following script, which generate random password and store it in file

pass1=</dev/urandom tr -dc _A-Z-a-z-0-9|head -c8
echo $pass1
echo "$pass1" >/tmp/a

Above script printing generated password through "echo $pass1" command. But nothing getting stored inside created /tmp/a file .

Please let me know whats wrong i am doing.

Mike Pennington
  • 8,305
  • 9
  • 44
  • 87
vnix27
  • 886
  • 2
  • 11
  • 19
  • Are you missing a pipe between `urandom` and `tr`? – jscott Jun 22 '12 at 15:57
  • @jscott, this is a [unique usage of the `<` operator](http://unix.stackexchange.com/questions/40837/bash-linux-random-cli-password-generator-and) – Mike Pennington Jun 22 '12 at 16:00
  • @MikePennington Thanks for that, I was trying to work through the syntax and what the expected output is... Both the OP's and your examples produce `tr` errors for me. – jscott Jun 22 '12 at 16:03

1 Answers1

1

It's not necessary to store the password in an intermediate variable. You only need this line in your shell script

</dev/urandom tr -dc _A-Z-a-z-0-9|head -c8 > /tmp/a

I saved as foo.sh, made permissions 755, and executed it under linux...

[mpenning@chestnut ~]$ uname -a
Linux chestnut.he.net 2.6.32.46-1-grsec #1 SMP Fri Sep 2 12:42:23 PDT 2011 x86_64 GNU/Linux
[mpenning@chestnut ~]$ ./foo.sh
[mpenning@chestnut ~]$ cat /tmp/a
qAUezN0-[mpenning@chestnut ~]$
Mike Pennington
  • 8,305
  • 9
  • 44
  • 87