Sponsored Content
Full Discussion: sftp syntax in script
Top Forums Shell Programming and Scripting sftp syntax in script Post 302381465 by markdjones82 on Friday 18th of December 2009 09:49:00 AM
Old 12-18-2009
Here is the syntax for an SFTP setup that I created that reads the commands out to a temp file and then runs the SFTP using the tmp file and removes. You could always keep the batch files as well, but I didn't want to have to manage tons of them. You need Passwordless Pubkey authentication though.

I bolded the part below. I don't believe SFTP can read teh STDIN like FTP scripts, but I could be mistaken.


Code:
#!/bin/bash

#SFTP_PUSH.sh
#
#       This script is for copying files from location where
#       they are dropped to SFTP server
#
#       Author: Mark Jones
#
#       Last updated: 10/12/09

#Before implementing you can run the create_dirs script to create the archive and log directories

##### Update information below ####
CLIENT=       #client name for directory location
FEEDNAME=     #feed name for directory location
ORIGLOC=  #pickup location
DESTSERV=  #destination server name
DESTUSER=    #username for destination server
DESTLOC=/

#### End User input ####
ARCHLOC=/ftp_custom/archives/$CLIENT/$FEEDNAME
LOGFILE=/ftp_custom/logs/$CLIENT/$FEEDNAME.log
GETDATE=`date`


#       echo start date to log

echo "Started script at $GETDATE" >> $LOGFILE

# Check if items in directory then execute, else (at bottom) exit

if [ "$(find $ORIGLOC -type f)" ]; then


#       List files out to log

echo " The following file was found and is about to be transferred..." >> $LOGFILE

ls -l $ORIGLOC >> $LOGFILE

#       Copy files to archive location

cp -p $ORIGLOC/* $ARCHLOC >> $LOGFILE

#       Copy files to new location using temporary sftp batch file

cd $ORIGLOC
echo cd $DESTLOC > /tmp/$FEEDNAME.sftp
echo 'mput *' >> /tmp/$FEEDNAME.sftp
echo bye >> /tmp/$FEEDNAME.sftp
sftp -b /tmp/$FEEDNAME.sftp $DESTUSER@$DESTSERV >> $LOGFILE
if [ $? -eq "0" ]; then
        echo Files successfully transfered at $GETDATE >> $LOGFILE
        rm -f $ORIGLOC/* >> $LOGFILE
else
        echo File transfer failed at $GETDATE >> $LOGFILE
fi

rm -fv /tmp/$FEEDNAME.sftp

# Echo finish date to log
echo "Finished script at $GETDATE" >> $LOGFILE
exit 0
 # End Script if directory empty
        else
        echo "No files to process $GETDATE" >> $LOGFILE
        echo "Finished script at $GETDATE" >> $LOGFILE
        exit 0
        fi


Last edited by markdjones82; 12-18-2009 at 10:58 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax error in script

I get this error when I try to run my script (BTW, this is a simple script I am supposed to write for my class) $ menuscript menuscript: syntax error at line 89 : `"' unmatched $ Here is the code (Any help is greatly appreciated) (Line numbers included) 1 #!/bin/ksh 2 ... (2 Replies)
Discussion started by: KindHead
2 Replies

2. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

3. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

4. Shell Programming and Scripting

CHECK SCRIPT SYNTAX

Hi everyone, i'd like someone chechk this script, i know it's very simple but it doesn't work good, let me tell you this script works over huge directories, maybe that's the problem, if somebody can give me other way to develop, or show me where it's the problem, i'll appreciate it. ... (9 Replies)
Discussion started by: Newer
9 Replies

5. UNIX for Dummies Questions & Answers

SFTP syntax without specifying private key location (no password)

Hi all, I need to connect using SFTP from Red Hat to Windows. Connection between servers work when I specify location of my private key in the script. However, I want to use syntax without private key location specified. I know this should work, as I found it in older scripts. Scripts were... (0 Replies)
Discussion started by: yavvie
0 Replies

6. Shell Programming and Scripting

Script syntax help

#!/bin/bash if ; then echo "Lipsa IP"; exit; fi i=1 ip=$1 while ; do if ; then rand=`head -$i pass_file | tail -1` user=`echo $rand | awk '{print $1}'` pass=`echo $rand | awk '{print $2}'` CMD=`ps -eaf | grep -c mysql` if ; then ./mysql $ip $user $pass & else sleep 15... (6 Replies)
Discussion started by: galford
6 Replies

7. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

8. Shell Programming and Scripting

Help with syntax of Python script

I added some fields to some existing code, and all was well. Just added a few more, and BAM. I've looked this over forever, but being a newbie to Python, I see NOTHING. The code generates syslog messages, and the new fields were added around "rtp_lapse*" . Any clues??? #!/usr/bin/python ... (4 Replies)
Discussion started by: gmark99
4 Replies

9. UNIX for Beginners Questions & Answers

Syntax error on script

Evening All (or morning for some), Could anyone have a look at the below and advise where i've going wrong with the syntax as i keep getting the below error while trying to run. Any help would be really apprecaited. ./testout: line 13: syntax error near unexpected token `else' ... (4 Replies)
Discussion started by: mutley2202
4 Replies

10. UNIX for Beginners Questions & Answers

Syntax in a simple script

I am in the process of writing a script. A very preliminary version is giving a syntax error. The script is #!/bin/bash #file1='./data/heu/hout1' exec 10<&0 exec < './data/heu/hout1' #file1='./data/heu/hout1- i=1 j=0 while read file1 do echo $file1 echo $i if then... (3 Replies)
Discussion started by: ngabrani
3 Replies
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. --font=desc Set the font description. Default is Monospace 12. --rtl Do rtl layout. --paper ps Choose paper size. Known paper sizes are legal, letter, a4. Default is A4. --bottom-margin=bm Set bottom margin in postscript points (1/72 inch). Default is 36. --top-margin=tm Set top margin. Default is 36. --left-margin=lm Set left margin. Default is 36. --right-margin=rm Set right margin. Default is 36. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --encoding=ENCODING Assume the documentation encoding is ENCODING. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 04:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy