Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-27-2008
Registered User
 

Join Date: Nov 2008
Location: Sydney, Australia
Posts: 1
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
Sponsored Links
  #2 (permalink)  
Old 11-28-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 2,668
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.
Sponsored Links
Closed Thread

Bookmarks

Tags
aix, sftp

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sftp -b doesn't read the batchfile kmw Shell Programming and Scripting 1 08-04-2008 02:18 PM
Automate batchfile generation for sFTP mpang_ Shell Programming and Scripting 0 04-26-2006 06:34 AM
Passing variables to sed jfisch Shell Programming and Scripting 3 03-07-2005 07:25 AM
Passing awk Variables gozer13 Shell Programming and Scripting 3 01-04-2005 04:32 PM
Passing Variables to Awk Bab00shka Shell Programming and Scripting 2 10-05-2004 08:18 AM



All times are GMT -4. The time now is 12:20 AM.


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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0