从 Linux 的 ftp 文件夹中加载 2 个最新文件
大家下午好, 我们有以下内容:
- 在服务器X上,我们有一些文件每15分钟(通常)产卵。该文件是2型-.csv和.log,
- 我们需要获取最新的2个文件并将它们带入服务器q,以解析它们以删除“:”,然后用“ - ”替换它;
- 将它们加载到FTP服务器中;
目前,代码是这样的:
`#!/bin/bash
X=ip.address
USER=myuser
SRC_DIR=/home/user/GETFILES/temp/
DEST_DIR=/home/user/GETFILES/input
date1=`date +%Y%m%d%H%M`
echo "======================================="
echo "======================================="
echo "======================================="
echo "Here we go $date1 !"
echo "======================================="
echo "======================================="
echo "======================================="
rsync -av --ignore-existing --include="patternforfiles\*.*" --exclude="*" -e "ssh -p port -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" $USER@$X:$SRC_DIR\* $DEST_DIR
\#Removing the ":"
cd temp/
for i in *:*; do
mv -- "$i" "${i//:/\-}"
done
**for i in `ls -Art SRC_DIR | grep filename | tail -n 2`;do**
**mv $SRC_DIR$i $DEST_DIR;**
**done**
sshpass -p "password" sftp -oPort=port [email protected] \<\< !
lcd /source/directory/
put filename\*.\*
bye
!`
bla bla 清洁任务
如果我作为单独的命令运行LS -Art零件工作正常,它为我带来了RSYNC路径的最后2个文件。如果我在脚本下运行,它将带来其他2个文件,然后使用上一个命令获得的文件……不知道为什么。 我在LS中错过了什么?
谢谢。
Good afternoon everyone,
We have the following :
- on server X we have some files spawning every 15 minutes (normally). This files are 2 type - .csv and .log
- we need to grab the most recent 2 files and bring them in the server Q, parsing them in order to remove ":" and replace it with "-" for example;
- load them in an ftp server;
The code is something like this at the moment :
`#!/bin/bash
X=ip.address
USER=myuser
SRC_DIR=/home/user/GETFILES/temp/
DEST_DIR=/home/user/GETFILES/input
date1=`date +%Y%m%d%H%M`
echo "======================================="
echo "======================================="
echo "======================================="
echo "Here we go $date1 !"
echo "======================================="
echo "======================================="
echo "======================================="
rsync -av --ignore-existing --include="patternforfiles\*.*" --exclude="*" -e "ssh -p port -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" $USER@$X:$SRC_DIR\* $DEST_DIR
\#Removing the ":"
cd temp/
for i in *:*; do
mv -- "$i" "${i//:/\-}"
done
**for i in `ls -Art SRC_DIR | grep filename | tail -n 2`;do**
**mv $SRC_DIR$i $DEST_DIR;**
**done**
sshpass -p "password" sftp -oPort=port [email protected] \<\< !
lcd /source/directory/
put filename\*.\*
bye
!`
bla bla
Cleaning task
If I run as a separate command the ls -Art part works fine, it bring me the last 2 files from the rsync path. If I run in under a script it brings 2 other files then the ones obtained with the previous command...and no idea why.
What am I missing with this for in ls?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表明 ls -Art 命令中每行有多个文件。
使用带有选项
-1
或-l
的ls
命令可以通过在单独的行中打印每个文件来解决此问题。Suggesting there are more then one file per line in the
ls -Art
command.Using
ls
command with option-1
or-l
solves this by printing each file in separate line.