简体   繁体   中英

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

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM