Ranger
Ranger

Reputation: 653

Problems with Linux scripting

I'm relativity new to scripting and such but I'm trying to make a script that will run at a particular time which will backup a network drive to a off site destination.

I have the commands working manually and have figured out the timing but I am getting the following error when trying to run the script:

    cd /volume1/Data
    lftp -u [username],[password] [Destination]
    Mirror [directoryname] -R -n

Can't cd to volume1/Data, line 3 mirror not found.

I've to checked the capitalization and spelling.

hmmm

Upvotes: 1

Views: 2297

Answers (3)

dogbane
dogbane

Reputation: 274838

You need to pass the mirror command to lftp:

cd /volume1/Data
user=joe
passwd=foo
host=myhost
dir=somedir

lftp -e "mirror $dir -R -n" -u $user,$passwd $host

Upvotes: 2

UUlum
UUlum

Reputation: 41

You can also use a "here document" like this:

#!/bin/sh
host=Destination
user=username
pass=password
folder=directoryname
cd /volume1/Data
lftp -u $user,$pass $host  << EOF
mirror $folder -R -n
EOF

Upvotes: 2

Michał Trybus
Michał Trybus

Reputation: 11804

Mirror is a lftp command, and the script executes it as if it were a shell command after the lftp process ends, which never happens, because the program is interactive, and waits for input. What you need to do is pass the lftp command to the standard input of lftp:

cd /volume1/Data 
echo "Mirror [directoryname] -R -n" | lftp -u [username],[password] [Destination]

Alternatively, you can use lftp's ability to execute scripts (check manual for -f option) and separate lftp commands into a separate file, then pass this file to lftp, or check out the -e option. It allows you to inline the lftp command into the parameter list.

Upvotes: 2

Related Questions