免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2687 | 回复: 4
打印 上一主题 下一主题

求助一个shell FTP 重定向的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-09-13 15:41 |只看该作者 |倒序浏览
本帖最后由 vinckdu 于 2011-09-13 15:45 编辑

下面一段代码,我把FTP 重定向插入到一个while循环中去,一直报错,syntax error: unexpected end of file
请各位帮忙看下什么原因,多谢!

#!/bin/bash
trap "echo 'the program interupted,pls run it again!';exit"  HUP INT QUIT TSTP


if test $# -lt 1
then
  echo " please enter the directory name !"
  exit
fi

mydir=$1
myid=`whoami`
echo " pls dont close this terminal until your stability finished"
echo " Your ENMTG  files(older than 1 day)  will move to FTP server 10.186.5.106:/export/home/ftpadmin/SVO/ENMTGLOG/$mydir/ "
echo -e "\r"



#create backup directory
(
echo "user svo svo"
echo "mkdir /export/home/ftpadmin/SVO/ENMTGLOG/$mydir/"
)|ftp -i -n 10.186.5.106

while true
do
  #filelist=`find /var/tmp/eNMTG_$myid* -mtime +1`
  filelist=`find /var/tmp/eNMTG_$myid*`
  for  file in $filelist
  do
   if test $file
    then
     gzip $file
    echo -e "\r"
  fi
  done
ftp -n -i <<EOF
   open 10.186.5.106
   user svo svo
   mkdir /export/home/ftpadmin/SVO/ENMTGLOG/$mydir/
   cd /export/home/ftpadmin/SVO/ENMTGLOG/$mydir/
   put *.gz
    EOF                                           ###########问题在这里

rm *.gz      
  sleep 3600
done

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
2 [报告]
发表于 2011-09-13 16:09 |只看该作者
第二个EOF没有缩进

论坛徽章:
0
3 [报告]
发表于 2011-09-13 16:25 |只看该作者
好像有个玩法是
<<-EOF
的话,后面那个EOF不用缩进?

论坛徽章:
0
4 [报告]
发表于 2011-09-13 16:35 |只看该作者
you are right ! thanks!

论坛徽章:
0
5 [报告]
发表于 2011-09-13 16:50 |只看该作者
本帖最后由 vinckdu 于 2011-09-13 17:01 编辑

又有个新的问题了!我把这个FTP编成了一个过程,然后在while do里面调用它,见最下面的代码,希望将文件传到FTP服务器上面去。
每次find 有文件match ,但是FTP服务器上面看文件没有,为什么呢??这个是我运行输出的log:请再帮忙看下!thanks .

pls dont close this terminal until your stability finished
Your ENMTG  files(older than 1 day)  will move to FTP server 10.186.5.106:/export/home/ftpadmin/SVO/ENMTGLOG/mytest/

/var/tmp/eNMTG_njiov01_1206.txt is transfering to FTP server ...
/var/tmp/eNMTG_njiov01_1206.txt transfer success!
delete /var/tmp/eNMTG_njiov01_1206.txt !
/var/tmp/eNMTG_njiov01_1206_1.txt is transfering to FTP server ...
/var/tmp/eNMTG_njiov01_1206_1.txt transfer success!
delete /var/tmp/eNMTG_njiov01_1206_1.txt !
/var/tmp/eNMTG_njiov01_1207.txt is transfering to FTP server ...
/var/tmp/eNMTG_njiov01_1207.txt transfer success!
delete /var/tmp/eNMTG_njiov01_1207.txt !
/var/tmp/eNMTG_njiov01_1207_1.txt is transfering to FTP server ...
/var/tmp/eNMTG_njiov01_1207_1.txt transfer success!
delete /var/tmp/eNMTG_njiov01_1207_1.txt !
/var/tmp/eNMTG_njiov01_1207_2.txt is transfering to FTP server ...
/var/tmp/eNMTG_njiov01_1207_2.txt transfer success!
delete /var/tmp/eNMTG_njiov01_1207_2.txt !
/var/tmp/eNMTG_njiov01_1207_3.txt is transfering to FTP server ...
/var/tmp/eNMTG_njiov01_1207_3.txt transfer success!
delete /var/tmp/eNMTG_njiov01_1207_3.txt !
/var/tmp/eNMTG_njiov01_1208.txt is transfering to FTP server ...
/var/tmp/eNMTG_njiov01_1208.txt transfer success!
delete /var/tmp/eNMTG_njiov01_1208.txt !
/var/tmp/eNMTG_njiov01_1208_1.txt is transfering to FTP server ...
/var/tmp/eNMTG_njiov01_1208_1.txt transfer success!
delete /var/tmp/eNMTG_njiov01_1208_1.txt !







#!/bin/bash
trap "echo 'the program interupted,pls run it again!';exit"  HUP INT QUIT TSTP



if test $# -lt 1
then
  echo " please enter the directory name !"
  exit
fi

mydir=$1
myid=`whoami`



move() {
echo $1 is transfering to FTP server ...
ftp -n -i <<EOF
open 10.186.5.106
user svo svo
cd /export/home/ftpadmin/SVO/ENMTGLOG/$mydir/
put $1
EOF
echo "$1 transfer success!"
}
echo " pls dont close this terminal until your stability finished"
echo " Your ENMTG  files(older than 1 day)  will move to FTP server 10.186.5.106:/export/home/ftpadmin/SVO/ENMTGLOG/$mydir/ "
echo -e "\r"



#create backup directory
(
echo "user svo svo"
echo "mkdir /export/home/ftpadmin/SVO/ENMTGLOG/$mydir/"
)|ftp -i -n 10.186.5.106

while true
do
  filelist=`find /var/tmp/eNMTG_$myid* -mtime +1`
# filelist=`find /var/tmp/eNMTG_$myid*`
  for  file in $filelist
  do
   if test $file
    then
     move $file
     echo " delete $file !"
  fi
  done

  
  sleep 3600
done
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP