Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux shell脚本,用于复制目录中文件的最后几行以附加到另一个目录中的文件_Linux_Bash - Fatal编程技术网

Linux shell脚本,用于复制目录中文件的最后几行以附加到另一个目录中的文件

Linux shell脚本,用于复制目录中文件的最后几行以附加到另一个目录中的文件,linux,bash,Linux,Bash,我编写了下面的shell脚本,用于复制目录中文件的最后几行以附加到另一个目录中的文件 cd /opt/grinder/svn/IAVS/GrinderLogs/GrinderBaseLogs/Lg2Logs GrinderLG1='rm101sys1lweb22' GrinderLg2='rm101sys1lweb23' fileCount=$(ls -l|wc -l) echo $fileCount for (( c=0; c<=$fileCount-2; c++ )) do

我编写了下面的shell脚本,用于复制目录中文件的最后几行以附加到另一个目录中的文件

cd /opt/grinder/svn/IAVS/GrinderLogs/GrinderBaseLogs/Lg2Logs
GrinderLG1='rm101sys1lweb22'
GrinderLg2='rm101sys1lweb23'
fileCount=$(ls -l|wc -l)
echo $fileCount
for (( c=0; c<=$fileCount-2; c++ ))
do
      Lines=$(more $GrinderLg2"-"$c"-data.log"|wc -l)
      Lines1=`expr $Lines - 1`
      `"tail -"$Lines1"f /opt/grinder/svn/IAVS/GrinderLogs/GrinderBaseLogs/Lg2Logs/"$GrinderLg2"-"$c"-data.log>>/opt/grinder/svn/IAVS/GrinderLogs/GrinderBaseLogs/"$GrinderLG1"-"$c"-data.log"`
      #exec $command
done
cd/opt/grinder/svn/IAVS/GrinderLogs/GrinderBaseLogs/Lg2Logs
研磨机LG1='rm101sys1lweb22'
GrinderLg2='rm101sys1lweb23'
文件计数=$(ls-l | wc-l)
echo$fileCount
对于((c=0;c
改为

  tail -"$Lines1"f /opt/grinder/svn/IAVS/GrinderLogs/GrinderBaseLogs/Lg2Logs/"$GrinderLg2"-"$c"-data.log>>/opt/grinder/svn/IAVS/GrinderLogs/GrinderBaseLogs/"$GrinderLG1"-"$c"-data.log
应该有用


在我的设置中,我按照以下方式进行了测试

#!/bin/sh
`"tail -10f filename"`
找不到给定的错误文件名

但是


这很好。

我已经回答了您的问题。如果您的问题不起作用,请通知我。尝试了您提到的更改,但仅在>>之前收到命令。它仅跟踪第一个文件,但未附加到目标文件。正常工作。使用-x选项执行shell脚本时,仅显示命令,直到>>但是,正如所料,我很喜欢这些文件。非常感谢32先生。
#!/bin/sh
`"tail -10f filename"`
#!/bin/sh
tail -10f filename