The UNIX and Linux Forums  

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
perl -write values in a file to @array in perl meghana Shell Programming and Scripting 27 06-07-2009 06:05 PM
[PERL] Running unix commands within Perl Scripts userix Shell Programming and Scripting 1 05-28-2008 07:06 PM
Define an alias with an embeded awk command ?? jfortes Shell Programming and Scripting 5 06-05-2007 02:03 PM
How to embeded programm within programm shankarao Shell Programming and Scripting 2 11-13-2006 09:29 PM
Replace Perl Module name in all Perl scripts rahulrathod Shell Programming and Scripting 2 12-02-2005 01:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-22-2003
bionicfysh bionicfysh is offline
Registered User
  
 

Join Date: May 2002
Posts: 21
Unhappy AWK embeded PERL

Hello Guys,

I am refering to this great forum once again for help.
After various attempts at this, I am still failing to obtain the desire effect.

I have to write a perl script which:
1- reads two values from the user (e.g name & passwd)
2- check each value against a file containing the authentic values
3- redirect the user according to his credentials, e.g
if this user is correctly identified (and granted he/she matches
another criteria), he is then directed to a page that only his
criteria allows him/her.
else (ie credentials incorrect)
user is directed to some error page.


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

So far I was able to:
open a file in perl
read the content of the file
read the two values ok

however, I don't know how to "awk" each field of the credential file so that I can put each entry inside a separate perl variable, and then check them against the user's ones.

the awk command I am trying to emulate is:
awk -F: '{print $x}' myfile

then I wish to send the content of $x into a perl variable :-(

N.B I realise that this forum is not meant to write me an entire program, and indeed I do not want that, since I actually want to learn how to do this. However I do welcome any help in this direction.


Thanks in advance

Da Bionic one !
  #2 (permalink)  
Old 09-22-2003
MIRV MIRV is offline
Registered User
  
 

Join Date: Sep 2003
Location: GA
Posts: 7
Are you trying to pull the content from myfile such as:

awk -F: '{print $1}' myfile

Are you looking output $1 into another file and then use that file as the input of your Perl script? If so, I think that you should be able to:
awk -F: '{print $1}' myfile >> $INPUT

Right? I am still rusty so I am asking as well. Sorry if I am not much help.
  #3 (permalink)  
Old 09-22-2003
bionicfysh bionicfysh is offline
Registered User
  
 

Join Date: May 2002
Posts: 21
AWK embeded perl

Hello Mirv, (and Hello Everyone)

Thanks for your fast response.
I am actually trying to read the content of myfile, somehow.
then from perl, extract fields from each record (file line).

so in normal unix script it looks like the awk script above, but I don't know if I can embed awk inside perl, and if so, how can I ?
otherwise, I am looking at using regular expressions, from perlre, and I found this:

if (/Time: (..) : (..) : (..)/) { # parse out values
$hours = $1;
$minutes = $2;
$seconds = $3;
}


Somehow, this retrieves each (colon separated) time field.
I would like to use something similar in order to retrive my fields.
e.g
myfile should look like this

login passwd credential
toto:totopass:totocred
mama:mamapass:mamacred
didi:didipass:didicred


Inside my perl script, I wish to:
1- open this file in READONLY
2- use some sort of look to scan through each record (file line)
3- retrieve each field, e.g $1 $2 $3
4- store each $x variable inside a perl variable (if the letter retrieving technique is not done in perl)



Many thanks for your efforts
  #4 (permalink)  
Old 09-22-2003
MIRV MIRV is offline
Registered User
  
 

Join Date: Sep 2003
Location: GA
Posts: 7
Like I said I am rusty...especially with shell scripting...but that's why I am here!

So is this going to be a patch process that you are going to be running and that's why you need this info? I'm just curious is all. Now there is another way to get those field you want without awk, it with the cut command. I believe it's cut -c but you can man cut to see all the switches. I am pretty sure that you can use awk inside of Perl. As far as implementing it, you would be better off asking one these gurus here. I think that you can use it just like in a KSH script but not sure. You could always create a test file and test it out, right? Now do you need to each field ($1, $2, and $3) to go into their own files respectively or would you only one file be enough for you to retreive your info?
  #5 (permalink)  
Old 09-22-2003
bionicfysh bionicfysh is offline
Registered User
  
 

Join Date: May 2002
Posts: 21
AWK embeded PERL

Hello MIRV (and HELLO EVERYONE)

Thanks for your reply.
I believe that you meant a batch, as opposed to a patch process ?
Well, am hoping to use it to secure my website. I have written a html form which prompts the user for his credentials, and then I get the perl script to check the credentials, before redirecting the user to the appropriate page.

I am really not sure how to integrate normal shell commands into a perl script. Earlier I even tried the [echo] command, but it is simply ignored.

Sorry, guys, but this is quite a desperate situation, and I would appreciate some help in this matter. (or at least some pointer)

Many thanks again

sosthene
  #6 (permalink)  
Old 09-23-2003
MIRV MIRV is offline
Registered User
  
 

Join Date: Sep 2003
Location: GA
Posts: 7
Yeah I meant batch..hehehe!! Sorry I cannot help man...Like I said before I am trying to get back into the swing of things, so if you find a good fix..please post it for us!


Thanks,
MIRV
  #7 (permalink)  
Old 09-23-2003
bionicfysh bionicfysh is offline
Registered User
  
 

Join Date: May 2002
Posts: 21
Unhappy AWK embeded PERL

Hey guys, just a quick question please:

how can I do this in perl ?

string:
"name : passwd"

retrieve "name" into variable $name
retrieve "passwd" into variable $passwd

This is in short what my problem is.

Many thanks

Da Bionic Fysh
Closed Thread

Bookmarks

Tags
regex, regular expressions

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 08:44 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