Solved

catch md5sum output

Posted on 2008-10-24
12
1,326 Views
Last Modified: 2013-12-26
I am writing a script that when run will ask the user to enter a password. The function will be something like:

function func_somethin() {
read -p "Enter User Password: " DBPASS
echo '${DBPASS}' | md5sum | grab MD5 here and place into variable of ${MD5PASS}
}

${MD5PASS} will be placed into a SQL query.

The problem I am having is catching the output and placing it into ${MD5PASS}. When I run it from command line I get this output..

[root@centbox trunk]# echo "password" | md5sum
286755fad04869ca523320acce0dc6a4  -

But I only need to grab the MD5. Any help would be great, as always I know I can get the best answers here with the level of knowledge amongst all of the experts. Thanks again
0
Comment
Question by:Sam Cohen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22796368
Hi,
what you need is
MD5PASS=$(echo  ${DBPASS} | md5sum)
wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22796503

Explanation>
The $([command]) construct is the equivalent to the old, ugly backticks ( `[command]`)  thing.
It opens a subshell, executes the command in it and gets itself replaced by the results of the command, so it can easily be assigned to a variable.
Hope I could help
wmp
 
0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 22796863
Here is the exact code I am using: (not all of the code, but for this portion - the script is almost 300lines long)

read -p "Enter Admin Password: " PASSWD

MD5PASS="$(echo  ${DBPASS} | md5sum) | echo ${MD5PASS}"

mysql -uadmin -p`cat /etc/psa/.psa.shadow` ${DBNAME} -e"INSERT INTO jos_users VALUES (62, 'Administrator', 'admin', 'your-email@email.com','$MD5PASS',    'Super Administrator', 0, 1, 25, '2005-09-28 00:00:00', '2005-09-28 00:00:00', '','');" | tee -a ${LOG}

When I check the database this is what I get
424b5395fb6b509ab9cda199a1ed201b  - | echo
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:Sam Cohen
ID: 22796870
I have also tried it without the quotes, and I get the same result.
0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 22796948
I created a test script with this code:

  read -p "Enter Admin Password: " PASSWD
  MD5PASS=$(echo  ${DBPASS} | md5sum)
  echo ${MD5PASS}

When I run it I get this output:
[root@centbox trunk]# ./md5test
Enter Admin Password: test
68b329da9893e34099c7d8ad5cb9c940 -
[root@centbox trunk]#
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22796980
Isn't that what you wanted?
wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22797002
Besides that, you prompt for PASSWD and then use DBPASS in the next step.
That's not correct.
wmp
0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 22797058
Yes, I just noticed that as well. Even when corrected it still dumps as 68b329da9893e34099c7d8ad5cb9c940 -

I need it to dump as

68b329da9893e34099c7d8ad5cb9c940

without the dash at the end. Sorry I didnt clarify
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 22797127
So you will have to issue
MD5PASS=$(echo  ${DBPASS} | md5sum | tr -d '-')
wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22797217
There is also a space before the dash.
To delete it too, Change tr-d '-' to tr -d ' -'   (means <space><dash>)
0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 22797313
Awesome! That is what I was looking for! thanks! Here is the final code which works great:


read -p "Enter Joomla Admin Password:" PASSWD
MD5PASS=$(echo -n ${PASSWD} | md5sum | tr -d '-')
echo ${MD5PASS}

Open in new window

0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22798043
You're welcome! Glad I could help you.
Norbert
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question