bash脚本prova.sh:第76行:语法错误:文件意外结束
我有下面的脚本,但我找不到错误。谁能帮帮我 具体来说,我将一个大文件拆分为不同的文件,然后压缩任何文件,移动它,并通过ftp重命名目标文件名发送 有些东西不起作用:( 一致: put${file}${7}.T${j}(+1) 我尝试用(+1)结尾的新文件名重命名该文件 问候bash脚本prova.sh:第76行:语法错误:文件意外结束,bash,eof,unexpectendoffile,Bash,Eof,Unexpectendoffile,我有下面的脚本,但我找不到错误。谁能帮帮我 具体来说,我将一个大文件拆分为不同的文件,然后压缩任何文件,移动它,并通过ftp重命名目标文件名发送 有些东西不起作用:( 一致: put${file}${7}.T${j}(+1) 我尝试用(+1)结尾的新文件名重命名该文件 问候 #!/bin/bash # configuration stuff # ${1} absolute path file # ${2} num_files # ${3} output_filename # ${4} ipM
#!/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
!/bin/bash
#配置材料
#${1}绝对路径文件
#${2}num_文件
#${3}输出文件名
#${4}ipMainframe ip用于放置文件
#${5}FTP用户名
#${6}FTP密码
#${7}目标文件名
如果[!$#==7];那么
#两个参数中不同的参数个数
回显“参数数量不正确”
echo“命令使用:LLP\u split\u gzip\u sendFTPandTrigger.sh绝对路径\u文件号\u块输出\u文件名ipMainframe用户FTP pwdFTP destinationFilename”
出口1
fi
如果[-f${1}];则
#如果文件存在
如果[${2}=~^[\-0-9]+$]&(${2}>0)),则
#如果工件数量为大于0的整数
#删除旧文件
echo“主目录=$home”
CMD=`rm-f'$HOME/“$3”*'`
如果[$?!=0];则
echo“无法删除主目录中的旧文件$home/llp_tmp*$home/“$3”*”
echo$CMD
fi
#计算分割的每个文件的行数
总行数=$(类别${1}| wc-l)
((每个文件的行数=(总行数+${2}-1)/${2}))
#分割实际文件,保留行。
CMD=`split-l“$lines\u per_file”“$1”“$HOME”/llp\u tmp`
如果[$?!=0];则
echo“分割文件错误:分割文件有问题。”
echo$CMD
出口3
fi
#对于每个拆分的文件,重命名并压缩它
i=1
对于$HOME/llp_tmp*中的文件,请执行以下操作
CMD=`mv“$file”“$3”“$i”`
如果[$?!=0];则
echo“无法重命名文件”
echo$CMD
出口5
fi
CMD=`gzip“$3”。$i”`
如果[$?!=0];则
echo“无法压缩文件$3.$i”
echo$CMD
出口6
fi
i=`expr$i+1`
完成
ftp-n${4}在+1
周围不需要括号
将其更改为:
put "${file}" "${7}.T${j}+1"
引用变量是很好的做法
另一个提示:您只需使用((j++)
)而不是j=`expr$j+1`
,您不会终止您的here文档。当我运行脚本时,我得到:
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}但是如果我将这一行替换为:CMD=ftp-n“$4”
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();