The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script(s) to Automate Tasks droppedonjapan Shell Programming and Scripting 2 05-21-2008 10:32 AM
script to automate mksysb via nim in AIX 5.3 barkath Shell Programming and Scripting 0 12-20-2007 06:46 PM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 10:15 AM
Automate batchfile generation for sFTP mpang_ Shell Programming and Scripting 0 04-26-2006 05:34 AM
automate the input in a script erwinspeybroeck UNIX for Dummies Questions & Answers 11 01-31-2002 10:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-01-2005
priyamurthy2005 priyamurthy2005 is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 4
automate sftp using unix script

Hi All,
I need to write a UNIX script that automates the sftp process. I should be able to do a sftp to a secure box and get a file from there. I am having a problem doing this because no matter what I do, when I run my script, I get a prompt at command line asking for a password. How could I automate this? Could someone give me a sample script?
Thanks in advance.
Priya
  #2 (permalink)  
Old 04-01-2005
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
This has been answered before in the forums here.
If you don't want to specify a password you need to generate a passwordless key with ssh-keygen and then copy the public key to the target host's ~/.ssh/authorized_keys file. This also has been discussed here before. Try a search.
  #3 (permalink)  
Old 04-01-2005
priyamurthy2005 priyamurthy2005 is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 4
Thank you so much dangral. I looked at your reply and looked at the sites you suggested. I am still at a loss. It asks me to use ssh. I tried that and created a public key file. Now it asks me for passphrase for public key file. I do not want any interactive mode at all. I somehow want it to automatically take the password for a file or something. I tried the following:
sftp -b passwordfile username@IP
The file "passwordfile" has passowrd stored in it. Still, it does not work. It first asks me for password interactively and only after I typed the password, it will execute the "passwordfile".
I looked on help for sftp and I was told that if I use non-interactive authentication, only then the above statement will work, meaning, it will take password for the batch file.
My question now is that: how do I achieve non-interactive authentication?

Thanks in advance.
  #4 (permalink)  
Old 04-01-2005
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
I think you have two issues here:

1) Achieving passwordless authentication
2) automating sftp

I will try to discuss one at a time. Forgetting about sftp for a second, in order to achieve passwordless authentication ( in your terms non-interactive authentication) you need to set up a key that does not have a password. See this link for tips on how to set that up.

However, please see this warning and tips on how to set it up to be secure. (Sorry for all the links)

Once you have verified passwordless authetication is working, you can now attempt to automate sftp. What the link in my previous post said is:
Quote:
However, it's nice to keep everything together in one file using "here documents." What you can do, is this:

#!/bin/sh
echo "OK, starting now..."
sftp -b /dev/stdin remotehost <<EOF
cd pub
...

Most modern Unix flavors provide a way to access the current process' standard streams via the filesystem. Linux has /dev/stdin; under Solaris, it would be /dev/fd/0 — yours may be different.
You would not be putting a password file after sftp -b, you would be putting your standard-in device or a file with all the ftp commands. So on solaris, your script might look like this:

Code:
  
  #!/bin/sh
  echo "OK, starting now..."
  sftp -b /dev/fd/0 remotehost <<EOF
  cd pub
  ascii
  get filename.txt
  bye
  EOF

Last edited by dangral; 04-01-2005 at 01:00 PM.. Reason: added security warning
  #5 (permalink)  
Old 04-01-2005
priyamurthy2005 priyamurthy2005 is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 4
Thanks again. Unfortunately, the command ssh-keygen does not work on my machine. It gives me the error:
ssh-keygen not found.
I guess I need to call my system admin and maybe get something installed, right???
  #6 (permalink)  
Old 04-20-2005
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
  
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Quote:
Originally Posted by dangral
I think you have two issues here:

1) Achieving passwordless authentication
2) automating sftp

I will try to discuss one at a time. Forgetting about sftp for a second, in order to achieve passwordless authentication ( in your terms non-interactive authentication) you need to set up a key that does not have a password. See this link for tips on how to set that up.

However, please see this warning and tips on how to set it up to be secure. (Sorry for all the links)

Once you have verified passwordless authetication is working, you can now attempt to automate sftp. What the link in my previous post said is:


You would not be putting a password file after sftp -b, you would be putting your standard-in device or a file with all the ftp commands. So on solaris, your script might look like this:

Code:
  
  #!/bin/sh
  echo "OK, starting now..."
  sftp -b /dev/fd/0 remotehost <<EOF
  cd pub
  ascii
  get filename.txt
  bye
  EOF

Hi,
When I tried to use the snippet of your code, I am unable to connect. the -b option used by you is not viable in solaris. here it stands for buffersize.

> sftp -h
Usage: sftp2 [-D debug_level_spec] [-B batchfile] [-S path] [-h]
[-V] [-P port] [-b buffer_size] [-N max_requests]
[-c cipher] [-m mac] [-4] [-6] [-o option_to_ssh2]
[user@]host[#port]
> sftp -V
sftp: F-Secure SSH 3.1.0 (build 12) on sparc-sun-solaris2.8
>

Thanks
Rishi
  #7 (permalink)  
Old 04-20-2005
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
You are using F-Secure sftp. The version I was referring to is OpenSSH.
Try using -B instead of -b.
Sponsored Links
Closed Thread

Bookmarks

Tags
linux, linux commands, mtime, sftp script, solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0