Generate two random symbols for mysql password in bash


Staff member
Hi I have a bash script I wrote for my plesk installation.

It triggers when a new subscription is created and does the following:

<li>Generates a password in a given format using two random symbols</li>
<li>Creates the db in plesk via cli</li>
<li>Downloads and unpacks wordpress to the httpdocs dir of that subscirption</li>
<li>Configures the wp-config.php for the site</li>
<li>Mails me the config details</li>

One problem though is sometimes I generate two symbols that seem to invalidate my password string. I think it's because some symbols need escaping in bash and it's not happening. Is there a way I can randomly grab two symbols from an array of "allowed" symbols?

Here is my genPassword() function

genpasswd() {
local pass=`cat /dev/urandom | tr -cd "[:punct:]" | head -c 2`
echo "$pass"
echo "INFO: genpasswd() ran successfully" &gt;&gt; /usr/run.log