问题描述
你怎么做的所有的文件后,wget的删除服务器中的文件?结果
我理解的删除命令的作品,当你做了一个ftp到服务器,但我无法运行shell脚本时使用的命令。下面是我的脚本,请让我知道什么是错的吧。
#!/斌/庆典文件清单='LS * 20120330 *
在文件列表$文件
做
FTP -vn< $主机> << EOFD
报价的<用户名>
报价PASS<&通GT;
二进制
LS -lrt * 20120330 *
删除文件列表$
放弃
EOFD
DONE
您想
为* 20120330 *文件
而不是环比字面的话 LS
和 * 20120330 *
。如果您的实际使用情况多,复杂得多,有可能是你想在一个变量中的文件列表的一个原因,但我的猜测是,你不这样做,永远不会。
(什么你可能会想是
在`文件LS * 20120330 *`
不过,这也是错误的,因为不同但相关的原因。另请参见 http://porkmail.org/era/unix/award.html#ls一>)
四角切圆,你可能会更好过创建这将删除所有的文件名,而不是为每创建一个新的FTP会话文件要删除脚本;
#!/斌/庆典dellist =
NL ='
'#是啊,NL是在单引号换行符
在* 20120330 *文件
做
dellist =删除文件$ $ NL
DONE
FTP -vn< $主机> << EOFD
报价的<用户名>
报价PASS<&通GT;
二进制
LS -lrt \\ * 20120330 \\ *。
$ dellist
放弃
EOFD
How do you delete a file in a server after doing a wget of all the files?
I understand the delete command works, when you are have done a ftp into the server, but I am unable to use the command while running a shell script. Below is my script, kindly let me know what is wrong in it.
#!/bin/bash
filelist='ls *20120330*'
for file in $filelist
do
ftp -vn <$hostname> <<EOFD
quote USER <username>
quote PASS <Pass>
binary
ls -lrt *20120330*
delete $filelist
quit
EOFD
done
You want
for file in *20120330*
rather than a loop over the literal words ls
and *20120330*
. If your real use case is much, much more complex, there could be a reason you want the file list in a variable, but my guess is that you don't, and never will.
(What you were probably thinking was
for file in `ls *20120330*`
but that is also wrong, for different but related reasons. See also http://porkmail.org/era/unix/award.html#ls)
Tangentially, you are probably better off creating a script which deletes all the file names, rather than creating a new ftp session for each file you want to remove;
#!/bin/bash
dellist=
nl='
' # yeah, nl is a newline in single quotes
for file in *20120330*
do
dellist="delete $file$nl"
done
ftp -vn <$hostname> <<EOFD
quote USER <username>
quote PASS <Pass>
binary
ls -lrt \*20120330\*
$dellist
quit
EOFD
这篇关于使用shell脚本删除文件在服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!