Improve company productivity with a Business Account.Sign Up

x
?
Solved

PERL execution inside shell script / replace in file

Posted on 2006-11-26
8
Medium Priority
?
295 Views
Last Modified: 2010-04-21
Okay, I have a function that was written in PERL, and I could try to convert it to shell but I think it would be easier just to use a PERL script and have it print the code into the shell, but I am having troubles getting it to work. Here is the PERL script:

encrypt.pl
---------------------------------------------
#!/usr/bin/perl

@palace_key = ( 55,197,96,114,205,165,11,6,209,249,203,60,87,12,13,27,121,30,45,114,180,4,179,96,178,128,221,137,160,237,242,132,124,250,196,153,159,39,237,222,108,222,30,184,72,52,100,41,118,165,1,134,33,11,191,176,153,237,32,45,117,66,76,106,192,117,126,137,51,0,101,130,3,4,147,61,87,74,170,47,165,213,116,189,215,49,218,131,150,226,24,89,238,32,83,36,61,136,171,119,74,153,185,4,225,211,157,208,137,191,137,68,50,100,199,46,147,51,213,107,41,149,187,59,130,150,61,96,38,208,132,91,69,90,139,76,90,60,91,138,88,148,184,155,19,219,107,190,26,10,96,115,116,85,231,89,176,186,68,118,172,226,133,22,196,16,83,151,56,192,238,168,6,66,169,27,189,210,151,226,221,37,218,165,68,199,32,81,58,251,146,148,23,113,47,2,85,96,150,181,38,76,87,247,139,70,120,25,226,182,96,143,208,247,148,105,4,45,197,65,210,64,131,137,103,199,238,245,93,167,137,49,215,146,82,87,216,167,16,246,211,20,138,18,118,127,26,226,23,213,177,255,126,130,216,50,179,137,29,178,68,106,120,175,15,35,249,100,122,59,122,19,33,80,134,128,7,71,152,188,132,36,110,224,171,132,222,220,1,32,237,3,2,153,163,47,158,137,103,3,105,197,165,46,18,177,84,95,211,54,249,128,220,55,95,35,105,178,203,57,153,123,233,89,99,40,9,5,182,146,170,69,121,84,212,227,45,107,108,90,167,41,231,108,102,149,64,201,45,206,51,57,85,102,202,126,209,122,192,32,64,9,78,41,179,222,9,205,153,174,251,24,173,115,213,126,186,2,91,143,92,163,249,169,43,242,99,222,152,47,38,153,40,202,190,239,119,114,174,200,93,41,114,108,42,24,59,139,161,21,172,30,93,9,72,125,221,44,171,138,7,228,74,164,107,150,17,136,205,156,48,21,207,85,18,241,130,76,4,36,236,168,174,210,28,46,28,18,66,154,232,32,100,92,191,222,232,244,229,76,119,228,81,176,38,218,167,134,243,16,180,134,232,14,121,145,78,222,117,123,213,209,215,170,22,189,91,3,165,49,56,147,51,102,242,14,111,16,168,216,53,149,80,45,161,63,253,6,9,144,134,204 );

sub palace_encrypt
{
local $lastchar = 0;
local $rc = 0;
local @bs;
for($i=length($_[0])-1; $i>=0; $i--) {
      local $b = ord(substr($_[0], $i, 1));
      $bs[$i] = $b ^ $palace_key[$rc++] ^ $lastchar;
      $lastchar = $bs[$i] ^ $palace_key[$rc++];
      }
return join("", map { chr($_) } @bs);
}

sub encode_escaped
{
local $str = $_[0];
$str =~ s/\\/\\\\/g;
$str =~ s/([^A-Za-z0-9\.\\])/sprintf("\\%2.2X", ord($1))/ge;
return $str;
}

print &encode_escaped(&palace_encrypt($ARGV[0]));

------------------------------------------------------------------------------

I am trying to use the encrypted output inside a shell script that will replace
OWNERPASSWORD "X"
with
OWNERPASSWORD "encyptedstring"

where encryptedstring is the return of &encode_escaped(&palace_encrypt($ARGV[0]))


The problem is that I try to run perl -e encrypt.pl owner and it doesnt seem to correctly work. I realize it might just be easier to do the whole thing in PERL, which is acceptable. But everything I read on search/replace in a file for PERL is all one-liners for the linux command line and not really for PERL script.
0
Comment
Question by:painfullyxpretty
  • 4
  • 4
8 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 18015987
perl encrypt.pl owner
0
 
LVL 85

Expert Comment

by:ozo
ID: 18016007
encyptedstring=`encrypt.pl $plaintextstring`
0
 

Author Comment

by:painfullyxpretty
ID: 18017163
I am not sure where you were getting at with your 2nd post, It gives me an error, ill paste you what I have so far...


#!/bin/sh
ENCRYPTEDPASSWORD=perl encrypt.pl owner
sed -i 's/OWNERPASSWORD "x"/OWNERPASSWORD "$ENCRYPTEDPASSWORD"/g' ./psdata/pserver
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:painfullyxpretty
ID: 18017166
This does not correctly store the output of the perl script to ENCRYPTEDPASSWORD, it also does not correctly use the ENCRYPTEDPASSWORD in the sed command either.
0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 18017273
#!/bin/sh
ENCRYPTEDPASSWORD=`perl encrypt.pl owner`
ESCAPEDPASSWORD=`echo $ENCRYPTEDPASSWORD | sed 's/\\\\/\\\\\\\\/g'`
sed -i 's/OWNERPASSWORD "X"/OWNERPASSWORD "$ESCAPEDPASSWORD"/g' ./psdata/pserver
0
 

Author Comment

by:painfullyxpretty
ID: 18017544
Okay, but this just prints the word "$ESCAPEDPASSWORD"    whereas it should be "5\8DT\85E" when using the word owner.
0
 
LVL 85

Expert Comment

by:ozo
ID: 18017568
Sorry, I thought I had typed
sed  's/OWNERPASSWORD "X"/OWNERPASSWORD "'"$ESCAPEDPASSWORD"'"/g'
0
 

Author Comment

by:painfullyxpretty
ID: 18017730
Thank youuuu. I know you answered the question in the first reply but you helped me along so A+++++
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…

595 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