Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a file with LFTP using variables

I'm trying to delete a file from an FTP server in my shell scrip using LFTP, but for some reason it will not use my variables, and takes them as literals.

The code:

USERNAME="theuser"
PASSWORD="verygoodpassword"
SERVER="example.com"
BACKUPDIR="thebackups"
FILETODELETE="uselessfile.obsolete"

lftp -e 'rm /${BACKUPDIR}/${FILETODELETE}; bye' -u $USERNAME,$PASSWORD $SERVER

What I want it to do is run:

lftp -e 'rm /thebackups/uselessfile.obsolete; bye' -u theuser,verygoodpassword example.com

But instead it runs:

lftp -e 'rm /${BACKUPDIR}/${FILETODELETE}; bye' -u theuser,verygoodpassword example.com

And of cause it can not find the literal file "/${BACKUPDIR}/${FILETODELETE}" on the FTP server and complains thus.

What am I doing wrong???

Cheers!

like image 635
Svante Avatar asked Mar 19 '12 15:03

Svante


People also ask

How use lftp command in Linux?

You can launch lftp by typing just lftp and then using an open command to take you to your target site or you can provide the target's name on the same line as lftp like I did.

What is the difference between lftp and ftp?

Special Features. LFTP stands out from most other command-line FTP clients with advanced features such as recursive mirroring and the ability to update entire directory trees and manage bookmarks. Several simultaneous sessions to different servers are implemented by assigning commands to slots in a separate shell.


1 Answers

That's because you are using simple quote instead of double quotes.

Change this and will work

USERNAME="theuser"
PASSWORD="verygoodpassword"
SERVER="example.com"
BACKUPDIR="thebackups"
FILETODELETE="uselessfile.obsolete"

lftp -e "rm /${BACKUPDIR}/${FILETODELETE}; bye" -u $USERNAME,$PASSWORD $SERVER
like image 103
Arnaud F. Avatar answered Oct 01 '22 08:10

Arnaud F.