Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

TheboL.wwwxxxxx, WWWXXXAPC , wwwxxn.xsss, wwwxxxapc, WWWXXX.VCBA, wwwxxx vba, wwwxxxdoco, Wwwxxx.APC, wwwxxx CN2, can't locate feature.pm in @inc (@inc contains

Links

XODOX
Impressum

#1: change password

Posted on 2005-10-11 17:19:23 by Kris

Hi
I need help for my script that change password placed in other file.

bp= /etc/passwd-
exec < $npl
while read line
do
#for users that exist in /etc/passwd
if grep `echo $line | cut -f 1 -d ':'` $bp
then

#take username from the file
a= echo $line | cut -f 1 -d ':'

#take password from the file
b= echo $line | cut -f 2 -d ':'

echo $b | passwd --stdin $a
fi
done

In this case passwd --stdin doesn't recognize the variable $a.
May you have other ideas for this isue.

Kris

Report this message

#2: Re: change password

Posted on 2005-10-11 22:40:36 by Bill Marcum

On Tue, 11 Oct 2005 15:19:23 GMT, Kris
<kris_mat@sbcglobal.net> wrote:
>
> #take username from the file
> a= echo $line | cut -f 1 -d ':'
>
> #take password from the file
> b= echo $line | cut -f 2 -d ':'
>
> echo $b | passwd --stdin $a
> fi
> done
>
> In this case passwd --stdin doesn't recognize the variable $a.
> May you have other ideas for this isue.
>
The variable $a is empty because you wrote a space after the = sign and
you didn't use ` ` or $( )

--
It's documented in The Book, somewhere...
-- Larry Wall in <10502@jpl-devvax.JPL.NASA.GOV>

Report this message

#3: Re: change password

Posted on 2005-10-11 23:44:27 by cfajohnson

On 2005-10-11, Kris wrote:
> Hi
> I need help for my script that change password placed in other file.
>
> bp= /etc/passwd-

You have assigned an empty string to bp and then tried to execute
/etc/passwd-. If you ran that, you would have received an error
message.

bp=/etc/passwd

> exec < $npl
> while read line
> do
> #for users that exist in /etc/passwd
> if grep `echo $line | cut -f 1 -d ':'` $bp
> then
>
> #take username from the file
> a= echo $line | cut -f 1 -d ':'

That should be:

a=`echo $line | cut -f 1 -d ':'`

But if you are using a POSIX shell (such as bash or ksh), you
don't need cut, which will slow down your script:

a=${line%%:*}

> #take password from the file
> b= echo $line | cut -f 2 -d ':'

The same applies here, but it's a little more complicated:

temp=${line#"$a":} ## remove the name and first colon
b=${temp%%:*}

> echo $b | passwd --stdin $a
> fi
> done
>
> In this case passwd --stdin doesn't recognize the variable $a.

A faster way would be to store the names from the password file in
a variable and look the names up in that:

set -- `cut -d: -f1 /etc/passwd`
names=" $* "

exec < $npl

## By setting IFS to a colon, read can split the lines for you
while IFS=: read -r a b stuff
do

## Using a here document prevents plaintext passwords from appearing
## in the output of ps
case $names in
*" $a "*) passwd --stdin "$a" <<-. ## Next 2 lines begin with tabs
$b
.
;;
esac
done

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
============================================================ ======
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>

Report this message

#4: Re: change password

Posted on 2005-10-13 18:23:34 by Kris

In article <raot13-2ub.ln1@rogers.com>, cfajohnson@gmail.com says...
> On 2005-10-11, Kris wrote:
> > Hi
> > I need help for my script that change password placed in other file.
> >
> > bp= /etc/passwd-
>
> You have assigned an empty string to bp and then tried to execute
> /etc/passwd-. If you ran that, you would have received an error
> message.
>
> bp=/etc/passwd
>
> > exec < $npl
> > while read line
> > do
> > #for users that exist in /etc/passwd
> > if grep `echo $line | cut -f 1 -d ':'` $bp
> > then
> >
> > #take username from the file
> > a= echo $line | cut -f 1 -d ':'
>
> That should be:
>
> a=`echo $line | cut -f 1 -d ':'`
>
> But if you are using a POSIX shell (such as bash or ksh), you
> don't need cut, which will slow down your script:
>
> a=${line%%:*}
>
> > #take password from the file
> > b= echo $line | cut -f 2 -d ':'
>
> The same applies here, but it's a little more complicated:
>
> temp=${line#"$a":} ## remove the name and first colon
> b=${temp%%:*}
>
> > echo $b | passwd --stdin $a
> > fi
> > done
> >
> > In this case passwd --stdin doesn't recognize the variable $a.
>
> A faster way would be to store the names from the password file in
> a variable and look the names up in that:
>
> set -- `cut -d: -f1 /etc/passwd`
> names=" $* "

Thank you Chris, I finished my script based on yours hints.

Kris

Report this message