从 Linux 的 ftp 文件夹中加载 2 个最新文件

发布于 2025-01-18 23:18:01 字数 1397 浏览 3 评论 0原文

大家下午好, 我们有以下内容:

  • 在服务器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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心舞飞扬 2025-01-25 23:18:02

表明 ls -Art 命令中每行有多个文件。

dudi@IL105567WIN:~$ ls -Art
.profile      .landscape  .sudo_as_admin_successful  dev               .motd_shown  .lesshsQ
.bashrc       .vimrc      .local                     .selected_editor  .hushlogin   .viminfo
.bash_logout  .vim        .cache                     .config           .lesshst     .bash_history

使用带有选项 -1-lls 命令可以通过在单独的行中打印每个文件来解决此问题。

dudi@IL105567WIN:~$ ls -1Art
.profile
.bashrc
.bash_logout
.landscape
.vimrc
.vim
.sudo_as_admin_successful
.local
.cache
dev
.selected_editor
.config
.motd_shown
.hushlogin
.lesshst
.lesshsQ
.viminfo
.bash_history

Suggesting there are more then one file per line in the ls -Art command.

dudi@IL105567WIN:~$ ls -Art
.profile      .landscape  .sudo_as_admin_successful  dev               .motd_shown  .lesshsQ
.bashrc       .vimrc      .local                     .selected_editor  .hushlogin   .viminfo
.bash_logout  .vim        .cache                     .config           .lesshst     .bash_history

Using ls command with option -1 or -l solves this by printing each file in separate line.

dudi@IL105567WIN:~$ ls -1Art
.profile
.bashrc
.bash_logout
.landscape
.vimrc
.vim
.sudo_as_admin_successful
.local
.cache
dev
.selected_editor
.config
.motd_shown
.hushlogin
.lesshst
.lesshsQ
.viminfo
.bash_history
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文