1833873 Members
1769 Online
110063 Solutions
New Discussion

Re: export variable

 
SOLVED
Go to solution

export variable

Hi2all,

I have some bad problem with a script who should check all my users whose password is the same as the login - name. I tried it with an ftp - server.

Here it is:
for USER in `/usr/bin/ypcat passwd | awk
-F: '{print $1}' `
do

{
ftp -n << !
open SERVER
user $USER $USER

!
}
done

The problem is, variable $USER isn´t seen in
the ftp - call.

thank
8 REPLIES 8
Rajeev  Shukla
Honored Contributor

Re: export variable

Use export USER and see if that works or
after
for USER in `/usr/bin/ypcat passwd | awk
-F: '{print $1}' `
do
export user=$USER
and then use $user in ftp script
Hoefnix
Honored Contributor

Re: export variable

It is also possible to create a .netrc file with the script and then call the "ftp " in your script. Check the return codes for the result if the username=password.
Graham Cameron_1
Honored Contributor

Re: export variable

This came up before.

Inside a here document (ie the bit between the "<<" and the "!", some characters, including $, need escaping.

Try changing "$USER" to "\$USER" both times.

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Graham Cameron_1
Honored Contributor

Re: export variable

My previous post was wrong.

Here's the earlier thread, doesn't look like it was resolved though....

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=242133

- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.

Re: export variable

Hello folks,

thank you very much for your reply!

I´d tried the export - dialog before I called the forum, but there it doesn´t work, and now it does?!?

How can I get the Returncode ( $? )??

Thanks

john korterman
Honored Contributor

Re: export variable

Hi,
if you run your script like this:
# sh -x
what error messages do you get?
Btw: does the first line: from "for USER" until and including the second backqoute appear on a single line?

regards,
John K.
it would be nice if you always got a second chance
Peter Nikitka
Honored Contributor
Solution

Re: export variable

Hi,
first: dont use the variable name USER - it is used internally on some systems.

second: Send the ftp-command via a pipe

(KSH-like):
for usr in $(ypcat passwd | awk -F: '{print $1}')
do
ftpout=$(print "open SERVER\nuser $usr $usr" | ftp -n 2>&1)
[ -z "$ftpout" ] && print $usr
done
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"

Re: export variable

Hey folks,

thank you all for help.

Greethings,

Alex