Passing variables: sftp using -b batchfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing variables: sftp using -b batchfile
# 1  
Old 11-27-2008
Passing variables: sftp using -b batchfile

Hi All,

I have created a script for an sftp transfer that works without a date variable being passed, I want it to work with a date variable being passed.

So, my initial script, mainsftp.sh, looks like this:
-----------------------------------------------------------------------
# Variables
#
ODAY=$1
LDIR1='/sftp/incoming'
USER1=username
MACHINE1=nnn.nnn.nnn.nnn
# Main
sftp -b ~/folder/sftpcmd.txt $USER1@$MACHINE1 <<EOF
-----------------------------------------------------------------------

File sftpcmd.txt looks like this:
----------------------------------------------------------------------
lcd /ftp/dir
get filename_*.csv
get filename_*.txt
bye
----------------------------------------------------------------------

Now - the above code works for me and will retrieve all files filename_*.csv and filename_*.txt however, for the purposes of my job, I want to change sftpcmd to look as follows, with $ODAY being passed as $1 to the main script:
----------------------------------------------------------------------
lcd /ftp/dir
get filename_$ODAY.csv
get filename_$ODAY.txt
bye
----------------------------------------------------------------------

My question is two-fold:
a) Is there a way to have the ftp commands in the batchfile above within mainsftp.sh? or if not
b) Is there a way to pass the $ODAY variable from mainsftp.sh to sftpcmd.txt

I'm working on an AIX server.

Thanks,
Julie
# 2  
Old 11-28-2008
a) Yes; you can just leave the -b and filename out of the command and insert the content of your sftp cmd file after the EOF, ending with an EOF like "here-scripts" do, like:

Code:
sftp host1 << EOF
cd
put ...
get ...
bye
EOF

b) When doing like explained in a) you can just substitute variables the normal way.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing -f with rm command in sftp

Is there any way I can pass -f with rm command in sftp? If I use it it treats -f as a file name to be removed. sftp> rm -f abcd Couldn't stat remote file: No such file or directory Removing /home/sdesai/-f Couldn't delete file: No such file or directory sftp> "rm -f" abcd Invalid... (2 Replies)
Discussion started by: Soham
2 Replies

2. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

3. UNIX for Dummies Questions & Answers

Sftp using batchfile - storing result local

I'm making an sftp-connection to a remote server. I want the result of an ls-command in a local file and the result of ls on another folder in another local file. Because everything has to go as fast a possible I wan't to do everyting in one connection. The command I use is : psftp -v -batch -b... (4 Replies)
Discussion started by: pistach
4 Replies

4. UNIX for Dummies Questions & Answers

Help on commands in sftp using BatchFile

Hi, The script didn't continue as "20130109" folder is already created on the destination server. Please help. Entry in script: cat > $filebatch << __EOF__ mkdir $current_date mkdir $current_date/$fpdomain cd $current_date/$fpdomain ls -l __EOF__ Error: sftp -b... (12 Replies)
Discussion started by: chococrunch6
12 Replies

5. UNIX for Dummies Questions & Answers

SFTP Passing without DSA Key check

Hi, I am trying to connect through SFTP. Though the DSA 2048 public key is installed in the server machine, the connection is established only with password authentication! When i turn off password authentication in sshd_config file the connection is not working. Please advise, Best... (0 Replies)
Discussion started by: Maharajan
0 Replies

6. UNIX and Linux Applications

SFTP without passing the password

Hi All, I am trying to do SFTP without passing the password. I did it by generating the Key pair on both source and destination servers but the problem is My script is running with BATCHADM user whereas I am doing SFTP using another username (sftp user1@destinationServer) due to which it is... (3 Replies)
Discussion started by: kaurr06
3 Replies

7. Solaris

SFTP passing variables date

Hi, Anyone can help me on how to solve my problem not getting the actual $DATE saying . Here my scripts; #!/bin/sh DATE='20110331' sftp -oUserKnownHostsFile=/.ssh/known_hosts -oIdentityFile=/.ssh/id_rsa -b /source/transfer.sh server1@sftp.com <<EOF #tranfer.sh put... (3 Replies)
Discussion started by: fspalero
3 Replies

8. Shell Programming and Scripting

sftp can't fine batchfile "No such file or directory"

Hi, I've got a C program that is using execlp to run a non-interactive sftp (using a batchfile) session to send some files to another system. Just before doing that, I create the batchfile called sftp_batch on the fly: V8_26_1:sun-->cat /workspace/sftp_batch cd /tmp/newsftp put test.file... (2 Replies)
Discussion started by: Fiaran
2 Replies

9. Shell Programming and Scripting

sftp -b doesn't read the batchfile

Several of our end-users need to send a file to our insurance carrier using ssh and sftp. We've put together a Windows VBS script that opens the ssh tunnel and calls sftp with the -b option pointing to a batch script in the same directory, however sftp doesn't seems to be reading from the... (1 Reply)
Discussion started by: kmw
1 Replies

10. Shell Programming and Scripting

Automate batchfile generation for sFTP

Hey all, I am writing a script for sFTP using batchfile option (-B). My script is supposed to monitor a certain directory for several files and when they are found I will send them to a testing server. So using a static batchfile wouldn't be feasible, I am just wondering if anyone can show... (0 Replies)
Discussion started by: mpang_
0 Replies
Login or Register to Ask a Question