开发者

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 err开发者_Go百科or 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 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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜