Solved

catch md5sum output

Posted on 2008-10-24
12
1,325 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
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remote install of MSI file 4 52
Linux Scripting 3 145
Need Nag Screen for Reboot if system up time is over 14 days 12 63
Using sort and uniq to pare down large syslog 6 54
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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…

821 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