LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 10: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, 10:44 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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 10:54 AM.
 
Old 11-05-2014, 12: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



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 06:45 PM
LXer: Restricting Users To SFTP Plus Setting Up Chrooted SSH/SFTP (Debian Squeeze) LXer Syndicated Linux News 0 09-06-2011 07:10 AM
How do I use sftp to upload my web site? (no sftp tar command) johnMG Linux - Networking 6 06-21-2005 09:14 PM
Files truncated by sftp/sftp-server at 65kb gato Linux - Networking 1 12-18-2003 10:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:21 PM.

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
Open Source Consulting | Domain Registration