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
problem while making ftp of a large file rprajendran UNIX for Dummies Questions & Answers 1 05-28-2008 01:19 AM
problem in making autossh between windows and solaris girish.batra UNIX for Advanced & Expert Users 7 04-10-2008 11:04 AM
problem in making file name from date command girish.batra Shell Programming and Scripting 2 02-13-2008 03:50 AM
Problem in making shell script girish.batra Shell Programming and Scripting 4 02-08-2008 09:10 AM
DDD making problem azazel11998 High Level Programming 0 03-10-2005 07:10 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 Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 02-20-2008
girish.batra girish.batra is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 73
problem in making sftp script

Dear all

I am bit new to shell scripting . I am implemented autossh between two sun solaris machines , so that when I use sftp it will not ask for the password.

Now I need to make shell script in which I have to transfer files from one server to another server automatically through root user. I try to make shell script for automatic transfer of files through sftp.

#! /bin/sh
sftp server1
lcd /girish
cd /amit
mput *
bye

after executing this shell script I have been put to sftp> prompt. When I exit from sftp , it give me three error lcd,cd mput command not found. It does not transfer files.

Please correct my shell script. I would be greatful for that.
  #2 (permalink)  
Old 02-20-2008
andryk's Avatar
andryk andryk is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2003
Posts: 448
Quote:
Originally Posted by girish.batra View Post
Dear all

I am bit new to shell scripting . I am implemented autossh between two sun solaris machines , so that when I use sftp it will not ask for the password.

Now I need to make shell script in which I have to transfer files from one server to another server automatically through root user. I try to make shell script for automatic transfer of files through sftp.

#! /bin/sh
sftp server1
lcd /girish
cd /amit
mput *
bye

after executing this shell script I have been put to sftp> prompt. When I exit from sftp , it give me three error lcd,cd mput command not found. It does not transfer files.

Please correct my shell script. I would be greatful for that.
Hi,
Create a batchfile with all the commands you wish to run then
Code:
server2:/tmp>cat batchfile
lcd /tmp/src
cd /tmp/dst
mput *
bye
server2:/tmp>sftp -b batchfile server1
sftp> lcd /tmp/src
sftp> cd /tmp/dst
sftp> mput *
Uploading file1 to /tmp/dst/file1
Uploading file2 to /tmp/dst/file2
...
sftp> bye
a simple scp could have done the trick, its all up to ya
  #3 (permalink)  
Old 02-20-2008
girish.batra girish.batra is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 73
Thank for your reply brother

I know that simple scp can do the trick also. But my requirement is to do through sftp.

Problem is not as simple as you think. Actually I have to make a script in which I have to transfer 24 files of approximately 4 to 5 mb each (text based). My shell script should check the number of bytes of each files at server one then after transfer of all these files to server two it should check that all files have been transfer and also have the same number of bytes as in server one.

kind regards
  #4 (permalink)  
Old 02-20-2008
girish.batra girish.batra is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 73
could anyone help me in this regard
  #5 (permalink)  
Old 02-20-2008
bobbygsk bobbygsk is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 90
Try the following code and let me know if it works for you
Quote:
echo "cd <dirname> \n put <file> \n quit" |sftp -v <remoteUserid>@<Server> 1>sftp1.log 2>sftp2.log
grep -i transfer sftp2.log
  #6 (permalink)  
Old 02-21-2008
girish.batra girish.batra is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 73
Dear Brother

First of all I would like to thanks for your reply. I have to modify your code a bit. Here is the code

At server1

# cat>abc
lcd /girish
cd /amit
mput *
bye

# cat>xyz
Sftp –B 131072 –b abc –v server2 1>sftp1.log 2>sftp2.log
grep -i uploading sftp1.log> output

When I execute the xyz file it gives me the files which are transfer & log into output file. –B used for fast transfer of files. If I don’t give the –v option even then it work. But when I use –v option, kindly tell me where and in which file sftp do the loging.

One more thing is that output file only show the output when all the files are transfer. But suppose when I dissconnected the network during the transfe of files then it will not show any output. I need a solution in which if something happen during transfer of files then either sftp start sending all the files again or from where it was left.
  #7 (permalink)  
Old 02-21-2008
bobbygsk bobbygsk is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 90
Girish,

Even without "-v" option the sftp works. But "-v" option gives the details of sftp connection and what exactly it is doing.
When you changed the code, you have grep'ed the 1st file (sftp1.log) instead of 2nd file (sftp2.log).

sftp1.log gives you the details of the command that is executed from the batch file but sftp2.log gives you the details of the connection such as servername, port, authentication of key, bytes per second and transfer status.
Sponsored Links
Closed Thread

Bookmarks

Tags
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 05:07 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