帮忙搞定一个shell

发表于:2007-06-08来源:作者:点击数: 标签:
我想从远端机器上的多个日期目录中自动ftp文件,写了一个shell,但不能实现,问题是ftp连接中不能执行shell只能执行ftp中的命令,虽然不能那样写,但可以让大家明白我的意思帮我另出方法,谢谢 ftp-i-nhostftp.txt ftp.txt内容 useruserpass hash cd/data2/d

我想从远端机器上的多个日期目录中自动ftp文件,写了一个shell,但不能实现,问题是ftp连接中不能执行shell只能执行ftp中的命令,虽然不能那样写,但可以让大家明白我的意思帮我另出方法,谢谢
ftp -i -n host < ftp.txt

ftp.txt 内容
user user pass
hash
cd /data2/detail       //此目录下有若干日期目录
for i in `ls -1`
do
cd $i
mget *
cd ..
done
bye

 sw_yp 回复于:2003-09-25 23:02:52
是不是日期目录定时生成,有相应的格式。
请说明

 iamjw 回复于:2003-09-26 11:25:44
日期目录不是自动生成的
远端机器/data2/detail 下内容
20030612/  20030730/  20030815/  20030818/  20030823/  20030906/  20030915/  20030722/  20030731/  20030816/  20030820/  20030824/  20030907/  20030916/  ......
如果到一个一个目录中去mget,太累了

 freshman 回复于:2003-09-26 14:46:39
有一个笨办法

for i in `ls -1` 
do   
   echo "user user pass 
             hash 
             cd /data2/detail
             cd $i
             mget * 
             by"  > ftp.txt
   ftp -i -n < ftp.txt
done

 iamjw 回复于:2003-09-26 18:00:03
您的办法一点不笨,在您的启发下我修改了一下,但只能从远端机器上put到本地机器上
for i in `ls -1`
do
if [ -d $i ]
then
   echo "user root root
   hash
   prompt off
   cd /tmp/dic
   mput * " > ftp.txt
   cd $i
ftp -i -n test < ../ftp.txt
   cd ..
else
exit
fi
done
 我还是想从本地机器上get,因为本地机器ftp是做了限制的只能get ,我的脚本是在另外的机器上测试的。

 shw2000 回复于:2003-10-20 20:41:07
safsdg

 大头虎 回复于:2003-11-14 20:03:52
可以现在本地机查询对方机器的目录,然后。。。
echo "user root root\nls\n"|ftp -i  -n remotehost |grep "^d"|awk '{print $NF}> file.list
awk 
while read pathname
do
     echo "user root root\ncd $pathname\nprompt\nmget *\n"|ftp -i -n remotehost
done <file.list

 iamjw 回复于:2004-03-18 16:08:40
$pathname可能有子目录,得想办法排除

原文转自:http://www.ltesting.net