Operating System - HP-UX
1753747 Members
4930 Online
108799 Solutions
New Discussion юеВ

Re: script to sftp using "variable" id

 
SOLVED
Go to solution
so.nimda
Super Advisor

script to sftp using "variable" id

Hi,

In the 'sftp' command, how do I replace the user ID with a variable?

sftp -b scriptname user@host

The "@host" is always the same. Many servers are sending files to this destination - the source user ID varies.

The intention is to use hostname to identify which user to do the sftp. This way, I can use the same script for different systems - just need to add the host and corresponding user id in an 'if-then-else' construct.

Is it possible?

Thanks
5 REPLIES 5
Mark McDonald_2
Trusted Contributor
Solution

Re: script to sftp using "variable" id

Have you tried simply using $user as you would in a script?

user=MarkM

sftp -b scriptname $user@host

Not near a box to try this at the moment though
Steven Schweda
Honored Contributor

Re: script to sftp using "variable" id

Uh, same as any other string and any other
variable?

user=fred
sftp -b scriptname "$user"@host

> The intention is to use hostname to
> identify which user to do the sftp.

Huh? Am I dense, or was that unclear?
Suraj K Sankari
Honored Contributor

Re: script to sftp using "variable" id

Hi,
What I understand that you want to send a file to some special users in the same host.
If this is right then take users name into a file
#cat myusers
user1
user4
user5
user8

now at the command prompt or save this code into a file
#cat myscript
for i in `cat myusers`
do
scp myfile $i@hostname
Done

now run this script as
#sh ./myscript

Suraj
so.nimda
Super Advisor

Re: script to sftp using "variable" id

@ mark, your solution worked... thanks...

@ Steven, different host use different user ID to sftp the file,
that's why I'm using the hostname to identify which user to use...
e.g. user John in host B12, user Pete in host J29, etc

@Suraj, thanks for the solution...
so.nimda
Super Advisor

Re: script to sftp using "variable" id

solution provided