Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

catch md5sum output

Posted on 2008-10-24
12
Medium Priority
?
1,335 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…
Suggested Courses

688 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