LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2014, 11:37 AM   #1
zachvac
LQ Newbie
 
Registered: Nov 2014
Posts: 2

Rep: Reputation: Disabled
Using variables in SFTP


ok I'm new to linux scripting but not new to programming.

Gotten most of this from google searches:
-----------------------------------------------------
#!/bin/bash

#argument, MMYYYY of previous month

#some stuff, $1 variable works fine here

sftp [location] << 'ENDSFTP'

cd [location]
get *$1*.txt
ENDSFTP
#other stuff down here
----------------------------------------------------------

If I want to use the input variables like $1 it works fine outside the sftp block, but inside when I try to do this it is not replacing $1 with the script argument variable. Basically someone else puts this text file on their server and as part of my script I want to be able to do this with an argument and not have to change the code every month. I have similar code to do this that is daily. One approach I've done is just getting *.txt and then deleting all the other ones using the variable outside the sftp block but there's got to be an easier way right?

Thanks.
 
Old 11-05-2014, 11:44 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
my opinion is that sftp prompts human users for keyboard input. whereas scp is designed for machine automation.

i think generically the problem is that the heredoc invokes a subshell in which $1 is not within its scope.

Last edited by schneidz; 11-05-2014 at 11:54 AM.
 
Old 11-05-2014, 01:09 PM   #3
zachvac
LQ Newbie
 
Registered: Nov 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
my opinion is that sftp prompts human users for keyboard input. whereas scp is designed for machine automation.

i think generically the problem is that the heredoc invokes a subshell in which $1 is not within its scope.
This makes sense. Do you know of any way I can get around it? With multiple commands I need to run while connected, can I use scp and if I could wouldn't I run into the same issue?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SFTP logging for Chroot on CentOS 6.2 with openssh-5.3 not working (internal-sftp) RatherBFishin Linux - Server 1 08-30-2012 07:45 PM
LXer: Restricting Users To SFTP Plus Setting Up Chrooted SSH/SFTP (Debian Squeeze) LXer Syndicated Linux News 0 09-06-2011 08:10 AM
How do I use sftp to upload my web site? (no sftp tar command) johnMG Linux - Networking 6 06-21-2005 10:14 PM
Files truncated by sftp/sftp-server at 65kb gato Linux - Networking 1 12-18-2003 11:29 AM


All times are GMT -5. The time now is 06:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration