Jump to content

[HELP] convert Perl script to Bash shell script

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Egypte

Egypte

    Newbie

  • Members
  • Pip
  • 2 posts
Hi everybody;

Need help converting the following Perl script to Bash shell script :
#!/usr/bin/perl -w

$SIG{INT} = 'IGNORE';

$SIG{TSTP} = 'IGNORE';

$SIG{TERM} = 'IGNORE';

$SIG{QUIT} = 'IGNORE';

print " Challenge1 : ";chomp($a=<STDIN>);

print " Challenge2 : ";chomp($b=<STDIN>);

while ($a ne  "123456" || $b ne "456789"){

print " Challenge1 : ";chomp($a=<STDIN>);

print " Challenge2 : ";chomp($b=<STDIN>);

}

I understand it's a simple while loop checks the STDIN values "Challenge1, and Challenege2" compared to "123456 and 456789" if correct it exit the loop or else ask for Challenges again. I'm pretty sure it's a nooby question and I'd better to learn Shell scripting but I really need it as soon as possible.

Also I've another question; How to store the reference values(i.e; 123456 and 456789) of Challenge1 and Challenge2 in an encrypted form say MD5 and even more save those values in another text file rather than showing them in the same shell script (i.e; compare STDIN to reference values in /home/user/challenges.txt).

Thanks in advance ;
# sorry if this post does not appear in a proper section -- newbie member.

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,721 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Welcome to CodeCall! As for your question - Here's a tutorial on how to program in bash's scripting language:

Advanced Bash-Scripting Guide

To write to a file, you can do something like this:

CHALLENGE1=...something...

CHALLENGE2=...blah...


SHACHALLENGE1= somehow get the SHA-2 of CHALLENGE1

SHACHALLENGE2= same for CHALLENGE1


# Don't forget the $

echo -e "$SHACHALLENGE1\n$SHACHALLENGE2" > challenges.txt



For MD5 (though I really suggest you use SHA-2) you're going to have to invoke a program from the command line to do that for you. I'm dead sure bash doesn't have native support for that.
sudo rm -rf /

#3
Egypte

Egypte

    Newbie

  • Members
  • Pip
  • 2 posts
Thanks dargueta for your help ;

Originally Posted by scottn @ programmingforums.org
A quick translation:

trap '' INT TSTP TERM QUIT

while [ "$a" != 123456 -o "$b" != 456789 ]; do

printf " Challenge1 : "; read a

printf " Challenge2 : "; read b

done


As for the md5 question, something like:

trap '' INT TSTP TERM QUIT

C=($(cat challenges.txt))

while [ "$a" != "${C[0]}" -o "$b" != "${C[1]}" ]; do

printf " Challenge1 : "; read a; a=$(echo $a | md5)

printf " Challenge2 : "; read b; b=$(echo $b | md5)

done


This assumes that "challenges.txt" looks like this:

f447b20a7fcbf53a5d5be013ea0b15af

d741dddf79cfc8677e3d0c8129e803f5


You can get that with, for example:

echo 123456 | md5 > challenges.txt

echo 456789 | md5 >> challenges.txt


this is what I was looking for ; and I'd like to share with you.
thanks again dargueta. rep+

Edited by dargueta, 24 April 2011 - 08:04 PM.
Please use [code][/code] tags next time.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users