The UNIX and Linux Forums  

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
sftp script in .sh koti_rama UNIX for Dummies Questions & Answers 2 08-22-2007 08:01 AM
sftp script coburn Shell Programming and Scripting 2 10-14-2006 02:06 PM
SFTP script HROMERO UNIX for Dummies Questions & Answers 0 10-19-2005 05:50 PM
sftp through script RishiPahuja Shell Programming and Scripting 1 04-21-2005 01:28 PM
sftp through a script skotapal Shell Programming and Scripting 1 05-23-2003 01:26 PM

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

Join Date: Jan 2009
Posts: 52
help with SFTP script in Except

Hi All,

I wrote a simple script in "Expect" for SFTP. I need to send a file every day to client site. Every thing is automated but it needs the password to work. I was told I should use "Except" so I don't need to enter the password.

I never wrote any script in Except, I am not sure if this is correct. But when I run it, still asks for the password. Please advise.


#!/usr/local/bin/expect
spawn sftp -b infofile user@prod
expect "xyzpasswd:"
send "shhh!\n";
interact

On the infofile... This is what I have.

On the lcd /home/citi
put abc012109.txt
quit

Last edited by samnyc; 01-22-2009 at 03:13 PM..
  #2 (permalink)  
Old 01-22-2009
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
It is Expect, not Except. Spelling is important in IT!

Try using autoexpect to generate your script. It records your session so that you can run it automatically the next time. Modify the generated script to remove any unnecessary stuff (usually it records too much).
  #3 (permalink)  
Old 01-22-2009
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Incidentally, if you are using SFTP, why not just use a public/private key pair for the authentication - no password required?
  #4 (permalink)  
Old 01-22-2009
samnyc samnyc is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 52
Sorry for the typo. I did spell it correctly in the script. I am going to try the key authentication, I have to check with the other administrator, and he is not friendly guy. But I guess I have no choice.
  #5 (permalink)  
Old 01-22-2009
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
Here's a sample script :


Code:
#!/usr/bin/expect

set timeout -1    # selects indefinite time to wait for login / response
                        # modify to 10, for instance, if you want the script to wait
                        # for 10 seconds to connect to the host.

set user user
set pass your-pass
set host the-host-name

spawn sftp [include whatever options you need here] $user@$host
expect assword:

send "$pass\r"
expect sftp>

send "command\r" # for example, hardcode "put file.txt"
expect sftp>

send "exit\r"
expect eof

  #6 (permalink)  
Old 01-22-2009
samnyc samnyc is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 52
Hi Sysgate,

Thank you so much for your help. I am able to log into the other server fine but I can't seem to put the file.

Message I get is...

put /home/citi/test.txtsftp> quit
File "/home/citi/test.txtquit" not found.
sftp>

After 10 seconds, it times out. I get my prompt back.
  #7 (permalink)  
Old 01-22-2009
samnyc samnyc is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 52
I got it working.... I added another set command. It's working now.

set AUTOHOME "/home/citi"

send "put $AUTOHOME/test.txt \r"

Thank again.
Closed Thread

Bookmarks

Tags
sftp script

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 05:19 PM.


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