The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Couldn't set locale correctly Mr Pink SUN Solaris 7 03-03-2009 08:16 AM
Secondary groups show in groups but don't show in id (Not working) zen03 HP-UX 4 12-31-2007 11:15 AM
Variable not working correctly. walsh_j Shell Programming and Scripting 3 05-30-2007 02:50 PM
if not working correctly 2dumb Shell Programming and Scripting 3 05-03-2007 02:38 PM
HP-UX will not boot correctly intern UNIX for Dummies Questions & Answers 5 05-24-2006 08:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2006
insania insania is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 30
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 (permalink)  
Old 07-01-2006
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
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 (permalink)  
Old 07-01-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
Thumbs up

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 (permalink)  
Old 07-01-2006
insania insania is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 30
That worked out great thank you guys for your help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0