2012-09-25 50 views
-1

我有下面的脚本,但我找不到错误。有人帮助我?bash脚本prova.sh:第76行:语法错误:意外的文件结尾

在具体的我在不同的分裂一个大文件,然后压缩所有文件,移动它,并通过FTP发送重命名目标文件名。

东西不工作:(

符合

: 放到$ {文件} $ {7} .T $ {}Ĵ(+ 1)

我尝试重命名文件(+1 )结束新的文件名

亲切的问候

#!/bin/bash 

# configuration stuff 

# ${1} absolute path file 
# ${2} num_files 
# ${3} output_filename 
# ${4} ipMainframe ip to put files 
# ${5} FTP username 
# ${6} FTP password 
# ${7} destination filename 

if [ ! $# == 7 ]; then 
     #number of parameter different of two 
     echo "Number of parameter incorrect" 
     echo "Command use: LLP_split_gzip_sendFTPandTrigger.sh absolute_path_file number_of_pieces output_filename ipMainframe userFTP pwdFTP destinationFilename" 
     exit 1 
fi 

if [ -f ${1} ]; then 
     # If file exists 
     if [[ ${2} =~ ^[\-0-9]+$ ]] && ((${2} > 0)); then 
       # if number of pieces is an integer > 0 
       #Remove old files 
       echo "home directory = $HOME" 
       CMD=`rm -f '"$HOME"/"$3"*'` 
       if [ $? != 0 ]; then 
         echo "Impossible to remove old files $home/llp_tmp* $home/"$3"* in home directory" 
         echo $CMD 
       fi 
       # Calculate line for every file splitted 
       total_lines=$(cat ${1} | wc -l) 
       ((lines_per_file = (total_lines + ${2} - 1)/${2})) 
       # Split the actual file, maintaining lines. 
       CMD=`split -l "$lines_per_file" "$1" "$HOME"/llp_tmp` 
       if [ $? != 0 ]; then 
         echo "SPLITTING FILE ERROR: problem to split file." 
         echo $CMD 
         exit 3 
       fi 
       #For every file splitted rename and zip it 
       i=1 
       for file in $HOME/llp_tmp*; do 
         CMD=`mv "$file" "$3"."$i"` 
         if [ $? != 0 ]; then 
           echo "Impossible to rename file" 
           echo $CMD 
           exit 5 
         fi 
         CMD=`gzip "$3"."$i"` 
         if [ $? != 0 ]; then 
           echo "Impossible to compress file $3.$i" 
           echo $CMD 
           exit 6 
         fi 
         i=`expr $i + 1` 
       done 
       ftp -n ${4} << EOF 

       j=1 
       user ${5} ${6} 
       for file in $3.*; do 
         put ${file} ${7}.T${j}(+1) 
         j=`expr $j + 1` 
       done 
       quit 
     else 
       echo "number of pieces second parameter must be more than 0." 
       exit 2 
     fi 
else 
     echo "absolute path first paramater doesnt exist" 
     exit 1 
fi 
exit 0 

回答

0

你并不需要大约+1括号。

将其更改为:

put "${file}" "${7}.T${j}+1" 

这是引用变量的好习惯。

另一个秘诀:与其j=`expr $j + 1`,你可以简单地使用((j++))

2

你并没有终止你的文件。当我运行你的脚本时,我得到:

gash.sh: line 72: warning: here-document at line 54 delimited by end-of-file (wanted `EOF') 
gash.sh: line 73: syntax error: unexpected end of file 

ftp -n ${4} << EOF是问题所在。你在这里的文件在哪里?

警告说,这一切,你没有一个EOF标记。请注意,这不能被隐藏! EOF必须位于“第0列”中,并且没有尾部字符,包括空格。

编辑:看来你要到一个FTP会话中使用的程序结构 - 我不知道这样做在Bash中的一种方式。 Perl有一个易于使用的FTP模块,你可以做到这一点,简单的例子:

use strict; 
use Net::FTP; 

my $ftp = Net::FTP->new ("hostname"); 
$ftp->login ("username", "password"); 
$ftp->binary(); 

for my $file (glob("$ENV{HOME}/llp_tmp*")) { 

    $ftp->put ($file); 
} 
$ftp->quit(); 
+0

,但如果我替代这次符合: CMD ='FTP -n “$ 4” << EOF' 给我同样的错误。 我的问题是在非交互模式下打开FTP会话,并把文件通过循环重命名,但我需要添加一个EOF,当我调用FTP -n命令不是交互模式。 你知道我该如何解决它? –

+0

编辑我的回覆... – cdarke

相关问题