perl replace command, stumped!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl replace command, stumped!
# 1  
Old 03-24-2009
perl replace command, stumped!

Ok,
I stole some code from a program that takess a hash of a password from PasswdMD5 and replaces it in the /etc/shadown file on a linux system. I run his program and it's fine. Well I took the same code and put it in another program that won't ask for prompgx and such and this code won't work:
Code:
perl -p -i.bk -e  's#^root:.*?:#root:$HASHLINUX:#' /etc/shadow

I validated $HASHLINUX has a good value in it. By not working I mean in the shadow file there is nothing in the column where the password hash value should be at.

Anyways I changed it to the below and it will work:
Code:
echo "perl -p -i.bk -e  's#^root:.*?:#root:$HASHLINUX:#' /etc/shadow" > /tmp/runpass
  sh /tmp/runpass

I really don't want to direct the statement to a external file and run it, but I cannot figure out why it won't work directly from the shell script.

Here's the whole procedure:
Code:
HASH=`/usr/local/bin/cryptpass $NEWPASS`
  HASHRHLX='$1$82gUYyNV$VWb5dxPAOqMFo9ZMWqFEW1'
  HASHRHLX=`echo "$HASH" | cut -f2 -d ":"`
  HASHLINUX=`echo "$HASHRHLX" | perl -p -e 's#\\$#\\\\\\$#g'`
  log "HASH = $HASH"
  log "HASHRHLX = $HASHRHLX"
  log "HASHLINUX = $HASHLINUX"
  echo "perl -p -i.bk -e  's#^root:.*?:#root:$HASHLINUX:#' /etc/shadow" > /tmp/runpass
  sh /tmp/runpass


Thanks for any help.

Last edited by benefactr; 03-24-2009 at 02:59 PM..
# 2  
Old 03-24-2009
Single quotes tell the shell to not interpolate shell variables, but use the string literally.
Code:
perl -p -i.bk -e  "s#^root:.*?:#root:$HASHLINUX:#" /etc/shadow

# 3  
Old 03-24-2009
Quote:
Originally Posted by pludi
Single quotes tell the shell to not interpolate shell variables, but use the string literally.
Code:
perl -p -i.bk -e  "s#^root:.*?:#root:$HASHLINUX:#" /etc/shadow

That was the issue, thanks alot!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Perl command to replace word in file...

Hi, I want to search for a specific word in file and replace whole line with new text. e.g. 1) I have file with below lines APP=ABCD 12/12/2012 DB=DDB 01/01/2013 I need perl command which will check for APP=$VAL and replace whole line with APP=$NEWVAL $NEWDT Simlarly need a... (2 Replies)
Discussion started by: mgpatil31
2 Replies

2. Shell Programming and Scripting

Sed/awk/perl command to replace pattern in multiple lines

Hi I know sed and awk has options to give range of line numbers, but I need to replace pattern in specific lines Something like sed -e '1s,14s,26s/pattern/new pattern/' file name Can somebody help me in this.... I am fine with see/awk/perl Thank you in advance (9 Replies)
Discussion started by: dani777
9 Replies

3. UNIX for Dummies Questions & Answers

Stumped .. is this a command line arg?

I need a bit of explanation: LogFile=${LOGS_DIR}/${1}_$$ I know: - LOGS_DIR is an environment variable - $$ is the PID ... but what is ${1} ?? Is it another method to access a command line variable, or the job name? Thanks! Jon (3 Replies)
Discussion started by: jdorn001
3 Replies

4. Shell Programming and Scripting

Perl command to replace path part of variable

I'm trying to replace path which is part of variable inside script file: FROM: ABC_HOME=$ABC_ROOT/abc/1.0 TO: ABC_HOME=$ABC_ROOT/abc/1.5 I'm using this: perl -pi -e 's\ABC_HOME=$ABC_ROOT/abc/1.0\ABC_HOME=$ABC_ROOT/abc/1.5\g' /apps/scripts/test.sh This command is not working because... (2 Replies)
Discussion started by: djanu
2 Replies

5. Shell Programming and Scripting

Command not found in shell script - stumped for 4 days

Hello, I like to begin with :wall:.. literally... It has been 4 days and I have no idea how to fix it. Environment - AIX 5.3 I wrote a script to call on ssh to log into another box via PKA to do something else. If I run the script on the terminal, it works 100%. If the SAP customised... (11 Replies)
Discussion started by: plonkagain
11 Replies

6. UNIX for Dummies Questions & Answers

how to use sed or perl command to find and replace a directory in a file

how to use sed command to find and replace a directory i have a file.. which contains lot of paths ... for eg.. file contains.. /usr/kk/rr/12345/1 /usr/kk/rr/12345/2 /usr/kk/rr/12345/3 /usr/kk/rr/12345/4 /usr/kk/rr/12345/5 /usr/kk/rr/12345/6 /usr/kk/rr/12345/7... (1 Reply)
Discussion started by: wip_vasikaran
1 Replies

7. Shell Programming and Scripting

Stumped

Hi, I'm pretty new to UNIX shell scripting and need some help. We have an Informatica interface that dumps any files that have errors into a directory. I need to check that directory for any of up to 9 files that might be in it and run a specific process for each file found. Here's what I... (3 Replies)
Discussion started by: JeffR
3 Replies

8. Shell Programming and Scripting

I Am Stumped, Please Help

I have a CSV file that I am trying to parse with awk in a table. I think I am going about this the wrong way. I can't get the awk arrays to output with a tab between them in one line. They print out vertically and I need them to print out horizontally. WHAT AM I DOING WRONG?? I want to know if... (21 Replies)
Discussion started by: timj123
21 Replies

9. UNIX for Dummies Questions & Answers

RegEx question has me stumped

Hi All, I'm fairly new to Regular Expressions, and have made some decent progress, but this one has me scratching my head. I'm trying to match the class name in my scripts as shown in the examples below. Any ideas? Thanks! -Mark :: Looking for a regex to match the red text :: import... (7 Replies)
Discussion started by: tolmark
7 Replies

10. IP Networking

httpd.conf - stumped

Have been asked to remove all images from being logged to the access_log ... where am I going wrong?<VirtualHost 123.456.789.99> ServerName www.somedomain.com.au DocumentRoot /agents/tts Redirect /wap http://somewap.com.au/traveler LogFormat "%v %h %l %u %t \"%r\" %>s %b" comonvhost... (2 Replies)
Discussion started by: Cameron
2 Replies
Login or Register to Ask a Question