Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Problem automating sFTP transfer using script in cron Post 302430732 by jyoung on Friday 18th of June 2010 01:43:02 PM
Old 06-18-2010
I don't believe you can run sftp in a script. I had to use expect to "automate" it. There are several postings on expect and its use. Good luck.

Here is some code that I put together from posts that I found here. Hope it helps.
Code:
#!../expect -f
# To make sftp non-interactive
# login is the first arg. password is the second arg
set force_conservative 1
if {$force_conservative} {
    set send_slow {1 .1}
    proc send {ignore arg} {
         sleep .1
         exp_send -s -- $arg
    }
}
set timeout -1
set password [lindex $argv 1]
set login [lindex $argv 0]
spawn sftp [lindex $argv 0]
match_max 1000000
expect "$login's password:"
send -- "$password\r"
expect "sftp>"
send -- "put -P /lsf1/hurdata/HMC*\r"
expect "sftp>"
send -- "ls -l\r"
expect "sftp>"
send -- "quit\r"
expect eof


Last edited by jyoung; 06-18-2010 at 03:25 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

automating sftp script

I have to write an automated sftp script which uses password authentication method to access the remote server. I want to pass the password as a parameter or to be included in the script itself, so that when i run the sftp script, it should not prompt me to enter the password. Thanks in advance... (1 Reply)
Discussion started by: Rajeshsu
1 Replies

2. Shell Programming and Scripting

How to transfer files (By using generic script) when using sftp

I have written generic script to transfer files from one machine to other machine(By passing the command line arguments like server name, user name ,location of the files, file names etc) but when i am using sftp, what are the things I have to specify in the code Is it necessary to specify... (0 Replies)
Discussion started by: gsri
0 Replies

3. UNIX for Dummies Questions & Answers

cron ? automating a script

Hi all. basically i need to run a script every 30 minutes. my script is simply an error report: errpt thats it, is there anyway to make this happen every 30 minutes without having to type errpt in, the script will get bigger as i add more things to do but just need to know how to... (8 Replies)
Discussion started by: hassanj
8 Replies

4. Solaris

Issues with automating SFTP

Hi We are trying to set up a non-interactive sftp to one of our clients to be able to transfer files to them. For the setup I logged into server1 as user1 and generated RSA public and private keys id_rsa and id_rsa.pub. Then I did an sftp to server2 as user2 and put the id_rsa.pub in the .ssh... (4 Replies)
Discussion started by: vnparo
4 Replies

5. Shell Programming and Scripting

Automating file transfer between two SSH enabled server.

Hi Experts, Few more words to the title, both the servers are ssh enabled but I have read only access to the second server, so I cannot automate SFTP process using RSA/DSA keys. I am using Control M to trigger the script and do not want any manual intervention to enter the password to complete... (4 Replies)
Discussion started by: nchourasiya
4 Replies

6. Shell Programming and Scripting

Shell script to transfer file via SFTP

Hi all, I'm trying to do a script to transfer file between my server and an external server via SFTP protocol. It doesn't use rsa key, but password. When I run the script, it throw back a prompt that request me to put the password. How should I do for automatic login? Pleaes help :( ... (2 Replies)
Discussion started by: Kapom
2 Replies

7. Shell Programming and Scripting

Sftp : not able to print the echo statements after the sftp transfer

I had the below sftp script working perfectly but the problem is I am not able to send the echo statements . #!/bin/sh echo "Starting to sftp..." sftp admin@myip << END_SCRIPT cd /remotepath/ lcd /localpath/ mget myfiles*.csv bye END_SCRIPT echo "Sftp successfully." echo echo... (11 Replies)
Discussion started by: scriptscript
11 Replies

8. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

9. Shell Programming and Scripting

Shell script, sftp logfile not showing transfer information

Hello, Recently I have changed some crontab scripts which I execute to do different tasks mainly transfering some files from one server to the other. The main change was the protocol from ftp transfer to sftp. Ftp server was the MS Windows default service, and Sftp server is an proprietary sw... (4 Replies)
Discussion started by: enux
4 Replies

10. UNIX for Beginners Questions & Answers

Execute a script after SFTP transfer

Hi All, I am having an issue with the script execution. I am having a SFTP process that send files to a location . I want to execute a script once it transfer the file to that location. Right now I am leveraging autosys file watcher to do that. Is there any way like MFT PPA that can execute... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies
ypxfr(1M)						  System Administration Commands						 ypxfr(1M)

NAME
ypxfr, ypxfr_1perday, ypxfr_1perhour, ypxfr_2perday - transfer NIS map from a NIS server to host SYNOPSIS
/usr/lib/netsvc/yp/ypxfr [-c] [-f] [ -C tid prog server] [-d ypdomain] [-h host] [-s ypdomain] mapname DESCRIPTION
The ypxfr command moves an NIS map in the default domain for the local host to the local host by making use of normal NIS services. It creates a temporary map in the directory /var/yp/ypdomain (this directory must already exist; ypdomain is the default domain for the local host), fills it by enumerating the map's entries, fetches the map parameters (master and order number), and loads them. It then deletes any old versions of the map and moves the temporary map to the real name. If run interactively, ypxfr writes its output to the terminal. However, if it is started without a controlling terminal, and if the log file /var/yp/ypxfr.log exists, it appends all its output to that file. Since ypxfr is most often run from the privileged user's crontab file, or by ypserv, the log file can retain a record of what was attempted, and what the results were. For consistency between servers, ypxfr should be run periodically for every map in the NIS data base. Different maps change at different rates: a map might not change for months at a time, for instance, and can therefore be checked only once a day. Some maps might change sev- eral times per day. In such a case, you might want to check hourly for updates. A crontab(1) entry can be used to automatically perform periodic updates. Rather than having a separate crontab entry for each map, you can group commands to update several maps in a shell script. Examples (mnemonically named) are in /usr/sbin/yp: ypxfr_1perday, ypxfr_2perday, and ypxfr_1perhour. Refer to ypfiles(4) for an overview of the NIS name service. OPTIONS
-c Do not send a "Clear current map" request to the local ypserv process. Use this flag if ypserv is not running locally at the time you are running ypxfr. Otherwise, ypxfr complains that it cannot communicate with the local ypserv, and the transfer fails. -f Force the transfer to occur even if the version at the master is not more recent than the local version. -C tid prog server This option is for use only by ypserv. When ypserv starts ypxfr, it specifies that ypxfr should call back a yppush process at the host server, registered as program number prog, and waiting for a response to transaction tid. -d ypdomain Specify a domain other than the default domain. -h host Get the map from host, regardless of the master. If host is not specified, ypxfr asks the NIS service for the name of the master, and tries to get the map from there. host must be a valid host name. -s ypdomain Specify a source domain from which to transfer a map that should be the same across domains. FILES
/var/yp/ypxfr.log Log file /usr/lib/netsvc/yp/ypxfr_1perday Script to run one transfer per day, for use with cron(1M) /usr/lib/netsvc/yp/ypxfr_2perday Script to run two transfer per day, for use with cron(1M) /usr/lib/netsvc/yp/ypxfr_1perhour Script for hourly transfers of volatile maps /var/yp/ypdomain NIS domain /usr/spool/cron/crontabs/root Privileged user's crontab file ATTRIBUTES
See attributes(5) for descriptions of the following attributes: ypxfr Only +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWnisu | +-----------------------------+-----------------------------+ ypxfr_1perday, ypxfr_1perhour, and ypxfr_2perday +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWypu | +-----------------------------+-----------------------------+ SEE ALSO
crontab(1), cron(1M), ypinit(1M), yppush(1M), ypserv(1M), ypfiles(4), attributes(5) SunOS 5.10 11 Mar 1998 ypxfr(1M)
All times are GMT -4. The time now is 02:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy