使用 SFTP 附加日期时重命名文件
我正在使用 sftp 将文件从 az/OS 系统发送到 Linux ftp 服务器。
一旦文件驻留在 Linux 机器上,我想将日期附加到文件名中。 (例如:filename.txt 变为 filename122308.txt)
我尝试使用“date +%m%d%y”执行“重命名”命令 - 文件已重命名,但标志未执行(文件名变为 filename'date +% m%d%y'.txt
'cp' 和 'mv' 命令不起作用...有什么想法吗
?
I'm sending a file from a z/OS system to a Linux ftp sever using sftp.
I want to append the date to the filename once the file resides on the linux box.
(Ex: filename.txt becomes filename122308.txt)
I have tried the 'rename' command using 'date +%m%d%y' - the file was renamed but the flags were not executed (The filename became filename'date +%m%d%y'.txt
The 'cp' and 'mv' commands do not work... any ideas?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
命令通过 JCL 控制卡发送。 我认为这种方法行不通。
The commands are being sent via JCL control card. I don't think this approach will work.
由于 sftp 没有运行 shell,因此无法执行
date
命令。 您可能必须在发送方评估所需的新名称,然后执行 sftp 重命名。另一种选择是将文件发送到队列区域(例如带有日期字符串的文件夹),并让 Linux 盒子上的脚本相应地移动/重命名接收到的文件。
Since sftp isn't running a shell, there's nothing to execute the
date
command. You're probably going to have to evaluate the new name you want on the sender's side, and then execute the sftp rename.Another option is to send the files into a queue area (like a folder with your date string), and have a script on the linux box move/rename the received files accordingly.
你可以通过命令行来完成吗? 存在执行 sftp 的选项...
...所以你可以执行...
Can you do it via the command line? The options exists to execute sftp as...
...so you might execute...
您可以访问 Linux 服务器吗? 在这种情况下,您只需重命名那里的文件即可。 例如,您可以使用 inotify 来监视目录,然后使用一个脚本在该目录中创建新文件时将日期添加到文件中。
这是 Python 中的一个简单示例(尽管大多数语言都有 inotify 绑定)。 您要监听的事件是 IN_CREATE。
Do you have access to the Linux server? In that case you could just rename the files there. You could for instance use inotify to monitor the directory, and then have a script that adds the date to files whenever a new file is created in that directory.
Here's a simple example in Python (although there are inotify bindings for most languages). The event you'll want to listen for is IN_CREATE.
不确定您的大型机 SFTP 客户端,但许多 SFTP 客户端支持使用! 运行本地操作系统命令的前缀。 因此,您可以在发送之前将文件复制到新名称,然后发送,然后删除副本。
例如:
如果空间很宝贵,请使用 mv 两次而不是 cp & R M。
Not sure about your mainframe SFTP client but many SFTP clients support using the ! prefix to run local operating system commands. So you can copy the file to the new name before sending, then send, then remove the copy.
E.g.:
If space is a premium, use mv twice instead of cp & rm.