Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

We have 5 servers running our code: A, B , C, D and E.

From a local machine, we sftp the file to A. Then

ssh id@A
su - applicationname
sftp id@A
get <file>
bye
tar -xzf <file>
logout
logout

The same procedure we apply for others B to E.

Is there any way we can simplify this using script?

We have requested linux team to provide passwordless authentication. But we don't know how to do sftp inside a SSH session using a script.

share|improve this question
2  
Use scp instead. –  jordanm Nov 18 '12 at 17:50

1 Answer 1

Best and easiest is to use scp instead of sftp.

If scp is really not an option, you can read sftp commands using a 'here document', but it is very hard to script around errors.

sftp username@server << %EOF%
ls
bye
%EOF%

%EOF% can be any word you want, as long as it starts and ends with a % and the last %EOF% must be at the start of a line.

For passwordless login, read up on 'ssh key authentication'.

Using sftp from within an ssh session sounds like overkill, sounds like doing double things. Why not initiate the copy from the local machine?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.