Variable with $ do not show correctly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable with $ do not show correctly
# 1  
Old 07-01-2006
Variable with $ do not show correctly

Hey guys i need help i have a script to push a password to a remote server the only problem is the $ENCRYPT variable has $'s in it (from the encrypted password in the shadow file) and they drop out when apending to the shadow file via the usermod command so

$1$Q/6a08n$EoAcBuR/YnoCQC shows up as

/6a08noAcBuR/YnoCQC


#!/bin/bash

userid=${1}
echo $userid
SHADOW=/etc/shadow
system=${2}

SHADOWENTRY=`grep "${userid}" ${SHADOW}`
echo ${SHADOWENTRY}

ENCRYPT=`echo ${SHADOWENTRY} | awk -F: '{print $2}'`
echo ${ENCRYPT}

ssh $system /usr/sbin/usermod -p ${ENCRYPT} ${userid}



Any help would be appreciated.

Sean
# 2  
Old 07-01-2006
To answer your question and keeping it within your script, one way of doing it is to run that string through sed and append a \ before each $.
I would do something like:
Code:
 ENCRYPT=$(grep ${userid} /etc/shadow | awk -F: '{print $2}' | sed 's/\$/\\\$/g')

When you echo ${ENCRYPT} locally, you'll see the whole string with the \ added before the $, but when you do the same remotely through ssh, you'll see the original string as it is in /etc/shadow

Now, I don't know how many times you need to do this, or with how many users, so depending on the circumstances, so there may be other better ways of doing what you need to do.
# 3  
Old 07-01-2006
MySQL

Here is a great resource written by Bruce Barnett
UNIX SHELL Quote Tutorial
I think this will help you to understand how to avoid such problems
# 4  
Old 07-02-2006
That worked out great thank you guys for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script worked correctly until I added variable :(

Hi everyone, I have been using a shell script for the last 6 months to copy a database from a POS system, then analyse the database and print the current sales total. This has worked flawlessly, the only issue was that I had hard coded the IP address of the POS and occasionally I would need to... (23 Replies)
Discussion started by: gjws
23 Replies

2. UNIX for Dummies Questions & Answers

Variable substitution to show up in ps and jobs.

when creating a for loop (or any other parameter) then using that paramter in a background command execution I only see the parameter name, not the value. I have tried eval and exec and a host of other options to try to get the text of the parameter showing, so i know what step is left... e.g.... (3 Replies)
Discussion started by: OoozyFoot
3 Replies

3. Shell Programming and Scripting

read variable from file show empty

Hi Folks, I am trying to read input from single line from a file and pass the read variable to one of the commands. However when I run the script it keeps the variable to be empty. I can however echo the variable ( but why it is empty when it goes to the command). Any help will be... (6 Replies)
Discussion started by: bhadu
6 Replies

4. Shell Programming and Scripting

Result of the grep is not storred correctly into the variable

I am facing a problem while storring the grep results into a variable. I need to count the occurence of the pattern \, in a file and store that in a variable. I have given the below command p=`grep -c '\\,' filename` But while echoing the variable, i am getting the total number of lines in... (2 Replies)
Discussion started by: renjithv
2 Replies

5. Shell Programming and Scripting

Making script show command (e.g. copy) being executed and variable substitution?

When script is running you only see when some of the commands are not successfull. Is there a way to see which command are executed and to show the substitution of variables as every line is executed ? (3 Replies)
Discussion started by: gr0124
3 Replies

6. Shell Programming and Scripting

Escaping ** correctly

Hello This should be easy, but bash is giving me headaches. At the command line the following command works: duplicity --include /home --exclude '**' / file:///foo Doing that from a script is not straightforward. Note that it is basically a requirement that I place the... (3 Replies)
Discussion started by: brsett
3 Replies

7. Shell Programming and Scripting

awk script to remove spaces - examples don't show up correctly

I have the following data from a manual database dump. I need to format the columns so that I can import them into an excel spread sheet. So far I have been able to get past the hurdles with vi and grep. Now I have one last issue that I can't get past. Here is an example of the data. Here is... (18 Replies)
Discussion started by: Chris_Rivera
18 Replies

8. Shell Programming and Scripting

Variable not working correctly.

Hi, I have a script where I am trying to set a local variable using the following, MYVAR="$NAME"_"$NAME2".txt where say, NAME = one NAME2 = two so I want the output one_two.txt but what I am getting is, two.txt basically the $NAME2 is overwriting, what am I doing wrong? ... (3 Replies)
Discussion started by: walsh_j
3 Replies

9. Shell Programming and Scripting

if not working correctly

Anyone have an idea why this if statement does not work correctly? "test2.sh" 18 lines, 386 characters #!/usr/bin/sh WARNING=80 CRITICAL=95 check_it() { if ] || ];then echo "YES ] || ]" else echo "NO ] || ]" fi } check_it 80.1 check_it 81.1 (3 Replies)
Discussion started by: 2dumb
3 Replies

10. HP-UX

HP-UX will not boot correctly

i've same failure too, but this command boot pri isl not work/not found Thanks! (1 Reply)
Discussion started by: pantas manik
1 Replies
Login or Register to Ask a Question