FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » please help me my output is screwy (linus related)

   
Author Topic: please help me my output is screwy (linus related)
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
quote:

#This script will generate a randomly created user id and password from the redhat linux dictionary

spc1=", "
spc2=" "


dpath=/usr/share/dict/words
grep -n '' $dpath > mywords
nwords=$(grep -c '' mywords)

>$2

echo "Names: User ID's: PASSWORDS CLASSIFIED:"
while read line
do

w=$(echo $line | cut -d' ' -f2 | cut -c1-3)
q=$(echo $line | cut -c1-3)

uida=$w$q
uidb=$uida

num=0
while grep "$uidb" $2 >& /dev/null
do
let "num=num+1"
uidb=$uida$num
done

# echo $uidb # >> $2

rnum1=$(perl randm.pl $nwords)
idnum1=^"$rnum1":
pw1=$(grep "$idnum1" mywords | sed 's/^[0-9]*://')
rnum2=$(perl randm.pl $nwords)
idnum2=^"$rnum2":
pw2=$(grep "$idnum2" mywords | sed 's/^[0-9]*://')

outline=$line"$spc2"$uidb$spc2$pw1$spc2$pw2
echo $outline

done < $1

cat $2

the output is:

quote:

Names: User ID's: PASSWORDS CLASSIFIED:
boivin, chris chrboi swingbys Pantheon
brown, kris kribro Ceratops discussed
cizauskas, nick nicciz monogynist tubas
cornell, philip phicor megacurie Brazee
cuplinskas, justin juscup antelopine peelcrow
deangelis, nick nicdea oarialgia pericarp
dewan, kanwaljeet kandew population pudic
glashan, jeff jefgla circumconic Peramium
godbout, samuel samgod dousing-chock ill-definedness
hall, michael michal zipless shoguns
jonas, tommie tomjon entwined leuko-
jones, tom tomjon over-cautious Roxanna
jonsson, tomas tomjon Bergh hyocholic
katsigiannis, nektarios nekkat annunciates unshowy
larivee, benoit benlar burthening revelational
manning, raymond rayman unsteered bravas
manson, rayleen rayman pycniospore Kanara
manzarek, ray rayman petrifies abintestate
moufawad, habib habmou Chrysops stall-feed
needelman, chris chrnee gestureless Newcastle
niedzviecki, benjamin bennie adminstration grannie
ohanian, arlen arloha letterheads THC
rideough, eric eririd nonmorality venosity
singer, mark marsin light-limbed wiking
viapiano, francis fravia balk knightess
zey, adam adazey thir monoplacular

Its not putting in the spaces I want, nor is it appending numbers, wtf am I doing wrong??
IP: Logged | Report this post to a Moderator
Miro
Member
Member # 1178

 - posted      Profile for Miro   Email Miro         Edit/Delete Post 
Please, STOP SHOUTING!

Thank you. [Smile] Sorry, I don't know anything about Linux.

Posts: 2149 | Registered: Aug 2000  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
there r u happy now? And do you actually know something about linux that can help?
IP: Logged | Report this post to a Moderator
Theaca
Member
Member # 8325

 - posted      Profile for Theaca   Email Theaca         Edit/Delete Post 
I don't know anything, but thank you for changing it. [Smile]
Posts: 1014 | Registered: Jul 2005  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
wow, I'm not sure I even want to try to figure out your logic in this . . .

And you even choose to invoke perl in it. If you're going to use perl, just freakin' use perl.

Also, let me introduce you to the notion of comments. Write a comment saying what each line is doing (less in a literal sense, more in an evocative sense).

I suspect its not creating the numbers because of output buffering -- the file isn't being created until after all the echos are "stacked". A quick "fix" might be to flush the output after each echo. However, this is both kludgy and will quickly become inefficient. Consider using some sort of array with string indices, either in the shell or using awk (awk would be far better) to hold how many times a given userid has been used.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
quote:

#This script will generate a randomly created user id and password from the redhat linux dictionary

spc1=", "
spc2=" "

#assings a path to a variable
#then it assigns numbers to the beginning of each line in the redhat dictionary
#counts the number of words total

dpath=/usr/share/dict/words
grep -n '' $dpath > mywords
nwords=$(grep -c '' mywords)

>$2

echo "Names: User ID's: PASSWORDS CLASSIFIED:" #output format
while read line #reads lines of names from file "clients"
do

w=$(echo $line | cut -d' ' -f2 | cut -c1-3) #assigns the first 3 chars from the last name to w
q=$(echo $line | cut -c1-3) #assigns the first 3 chars from first name to q

uida=$w$q #assigns w and q to uida
uidb=$uida assigns a double of uida to uidb

num=0 #initializes num to 0
while grep "$uidb" $2 >& /dev/null #if if finds a multiple of a userid do loop
do
let $num=$num+1 #assigns the value of num and increments it by 1 for each multiple usr id
uidb=$uida$num #the userid + the number becomes uidb
done

echo $uidb >> $2 #testing

#creates a random number by invoking pearl, and using grep, finds the line that matches the given number
#using sed, blanks out the number and the user id

rnum1=$(perl randm.pl $nwords)
idnum1=^"$rnum1":
pw1=$(grep "$idnum1" mywords | sed 's/^[0-9]*://')
rnum2=$(perl randm.pl $nwords)
idnum2=^"$rnum2":
pw2=$(grep "$idnum2" mywords | sed 's/^[0-9]*://')

outline=$line$spc2$uidb$spc2$pw1$spc2$pw2
echo $outline

done < $1

cat $2

I invoked pearl to get a random number, I don't know pearl so I don't code in it, I used pearl function because it was suggested to me.

quote:

boivin, chris
brown, kris
cizauskas, nick
cornell, philip
cuplinskas, justin
deangelis, nick
dewan, kanwaljeet
glashan, jeff
godbout, samuel
hall, michael
jonas, tommie
jones, tom
jonsson, tomas
katsigiannis, nektarios
larivee, benoit
manning, raymond
manson, rayleen
manzarek, ray
moufawad, habib
needelman, chris
niedzviecki, benjamin
ohanian, arlen
rideough, eric
singer, mark
viapiano, francis
zey, adam

a client list.
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
ok after fiddling around with some testing, I realize it is giving a number but its not outputting it with the $output variable, can aynone tell me whats wrong?
IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Write outline to stderr directly before you echo it. Ponder this. Try writing the pieces that seem wrong to stderr directly after their creation, and ponder this. Perhaps test other points.

This is called debugging.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
quote:

#This script will generate a randomly created user id and password from the redhat linux dictionary

#asgings a path to a variable
#then it assigns numbers to the beginning of each line in the redhat dictionary
#counts the number of words total

dpath=/usr/share/dict/words
grep -n '' $dpath > mywords
nwords=$(grep -c '' mywords)

>$2

echo "Names: User ID's: PASSWORDS CLASSIFIED:" > sec #output format
echo "" >> sec
echo "" >> sec
while read line #reads lines of names from file clients
do

w=$(echo $line | cut -d' ' -f2 | cut -c1-3) #assigns the first 3 chars from the last name to w
q=$(echo $line | cut -c1-3) #assigns the first 3 chars from first name to q

uida=$w$q #assigns w and q to uida
uidb=$uida #assigns uida to uidb
num=0 #initializes num to 0

while grep "$uidb" $2 >& /dev/null #if if finds a multiple of a userid do loop
do
let num++ #assigns the value of num and increments it by 1 for each multiple usr id
uidb=$uida$num #the userid + the number becomes uidb
done

echo $uidb > $2 #phony output that annoyed me, so now it is decoration

#creates a random number by invoking pearl, and using grep, finds the line that matches the given number
#using sed, blanks out the number and the user id


rnum1=$(perl randm.pl $nwords)
idnum1=^"$rnum1":
pw1=$(grep "$idnum1" mywords | sed 's/^[0-9]*://')
rnum2=$(perl randm.pl $nwords)
idnum2=^"$rnum2":
pw2=$(grep "$idnum2" mywords | sed 's/^[0-9]*://')

echo "$line $uidb $pw1 $pw2" | awk '{printf "%-14s %-14s %-14s %-20s %-20s \n", $1, $2, $3, $4, $5}' >> sec


done < $1

echo "Your file is now ready within the file "sec" in your PWD"

It is now complete.

quote:

Names: User ID's: PASSWORDS CLASSIFIED:


boivin, chris chrboi sugi Ante-nicene
brown, kris kribro slinkingly microhistochemical
cizauskas, nick nicciz disqualifications chromoctye
cornell, philip phicor relaster Ritch
cuplinskas, justin juscup raunge Tombalbaye
deangelis, nick nicdea sissyish grassplot
dewan, kanwaljeet kandew Race Commelinaceae
glashan, jeff jefgla volkswagen sabby
godbout, samuel samgod devitrifying matamata
hall, michael michal Trilbie incandescent
jonas, tommie tomjon nonlucrative Tasman
jones, tom tomjon1 Nyctanthes kindest
jonsson, tomas tomjon2 bell-metal Amargo
katsigiannis, nektarios nekkat procrastinatory wail
larivee, benoit benlar cardamine paravent
manning, raymond rayman Fante nonpropagandist
manson, rayleen rayman1 inconcoction uncompellable
manzarek, ray rayman2 apple-pie draftmanship
moufawad, habib habmou -log isometrically
needelman, chris chrnee clanfellow stonegall
niedzviecki, benjamin bennie thixotropic Ixelles
ohanian, arlen arloha contractee consentient
rideough, eric eririd lummy prowler
singer, mark marsin Humarock Catskills
viapiano, francis fravia outquaff quatty
zey, adam adazey nonpermitted heteropolarity

The problem was mostly due to output and some other stuff that I'll mention tomorrow after some rest.
IP: Logged | Report this post to a Moderator
HollowEarth
Member
Member # 2586

 - posted      Profile for HollowEarth   Email HollowEarth         Edit/Delete Post 
Blayne, did you every try posting this at a forum more dedicated to this kind of thing? I'm not trying to discourage you from posting it here, but you might find that there are more people who can help you at other forums.
Posts: 1621 | Registered: Oct 2001  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
... if I knew other forums.....
IP: Logged | Report this post to a Moderator
tern
Member
Member # 7429

 - posted      Profile for tern   Email tern         Edit/Delete Post 
LinuxForums.org and LinuxQuestions.org, as well as CodeNewbie.com.

Just google for Linux Newbie Forums.

Posts: 561 | Registered: Feb 2005  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2