使用 SFTP 附加日期时重命名文件

发布于 2024-07-10 00:25:01 字数 264 浏览 9 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(6

很酷不放纵 2024-07-17 00:25:01

命令通过 JCL 控制卡发送。 我认为这种方法行不通。

The commands are being sent via JCL control card. I don't think this approach will work.

流星番茄 2024-07-17 00:25:01

由于 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.

怪我入戏太深 2024-07-17 00:25:01

你可以通过命令行来完成吗? 存在执行 sftp 的选项...

sftp [[user@]host[:file [file]]]

...所以你可以执行...

export WHEN=`date +%m%d%y`
sftp theUser@theHost:filename$WHEN.txt filename.txt <<-!
thePassword
!

Can you do it via the command line? The options exists to execute sftp as...

sftp [[user@]host[:file [file]]]

...so you might execute...

export WHEN=`date +%m%d%y`
sftp theUser@theHost:filename$WHEN.txt filename.txt <<-!
thePassword
!
万劫不复 2024-07-17 00:25:01

您可以访问 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.

因为看清所以看轻 2024-07-17 00:25:01
#Establish a local variable to store the LOGINID to be used
export USERID=xxxxx                                                  
#Establish a local variable to store the Path/file location on Remote machine
export REMOTEPATH=/some/path/    
#Establish a local variable to store the NAME of the remote Server
export TARGET=192.168.0.xx
#Establish a local variable to store the new component of the file name (in
#this case, a modification of Date)
export WHEN=`date +%m%d%y`                                                  
#Demonstrate that the USERID variable is set properly by echoing it out to the
#StandardOut
echo "User "$USERID                                               
#Demonstrate that the TARGET variable is set properly by echoing it out to the
#StandardOut
echo "Target Server: "$TARGET                              
#Demonstrate that the REMOTEPATH / server variable is set properly by echoing
#it out to the StandardOut
echo "Target Path "$REMOTEPATH                                    
#Demonstrate that the WHEN / date name modication variable is set properly by
#echoing it out to the StandardOut
echo "Date component of file "$WHEN                                  
#Just echo out that we're about to do something useful
echo "Sending file to REMOTE"                                        
#Simulate the user typing out a command by using the "echo" command.  We use
#the $REMOTEPATH and $WHEN variables to modify "what the user types" but when
#we're done, echo passes information into SFTP just like the user were sitting
#there typing in the #commands.  In this case, it should send in 
#"put /local/path/file /some/path/fileName09092009.txt"
#That is provided as the command list to sftp because of the single "-" that 
#says "get my list of commands from standard-input"  The -vvv is for verbose 
#(lots of diagnostics) and then the $USERID@$TARGET uses the USERID and TARGET
#variables to connect as user-at-server for the exchange.
#A passwordless SSH authentication is already in place, so no password 
#is needed.
echo "put  /local/path/file $REMOTEPATH/fileName$WHEN.txt " | \
    sftp -b - -vvv $USERID@$TARGET
#Just echo out that we're about to do the next step and change file
#permissions.
echo "Changing file Permissions on REMOTE"                
echo "Done"                                          
#Establish a local variable to store the LOGINID to be used
export USERID=xxxxx                                                  
#Establish a local variable to store the Path/file location on Remote machine
export REMOTEPATH=/some/path/    
#Establish a local variable to store the NAME of the remote Server
export TARGET=192.168.0.xx
#Establish a local variable to store the new component of the file name (in
#this case, a modification of Date)
export WHEN=`date +%m%d%y`                                                  
#Demonstrate that the USERID variable is set properly by echoing it out to the
#StandardOut
echo "User "$USERID                                               
#Demonstrate that the TARGET variable is set properly by echoing it out to the
#StandardOut
echo "Target Server: "$TARGET                              
#Demonstrate that the REMOTEPATH / server variable is set properly by echoing
#it out to the StandardOut
echo "Target Path "$REMOTEPATH                                    
#Demonstrate that the WHEN / date name modication variable is set properly by
#echoing it out to the StandardOut
echo "Date component of file "$WHEN                                  
#Just echo out that we're about to do something useful
echo "Sending file to REMOTE"                                        
#Simulate the user typing out a command by using the "echo" command.  We use
#the $REMOTEPATH and $WHEN variables to modify "what the user types" but when
#we're done, echo passes information into SFTP just like the user were sitting
#there typing in the #commands.  In this case, it should send in 
#"put /local/path/file /some/path/fileName09092009.txt"
#That is provided as the command list to sftp because of the single "-" that 
#says "get my list of commands from standard-input"  The -vvv is for verbose 
#(lots of diagnostics) and then the $USERID@$TARGET uses the USERID and TARGET
#variables to connect as user-at-server for the exchange.
#A passwordless SSH authentication is already in place, so no password 
#is needed.
echo "put  /local/path/file $REMOTEPATH/fileName$WHEN.txt " | \
    sftp -b - -vvv $USERID@$TARGET
#Just echo out that we're about to do the next step and change file
#permissions.
echo "Changing file Permissions on REMOTE"                
echo "Done"                                          
攒眉千度 2024-07-17 00:25:01

不确定您的大型机 SFTP 客户端,但许多 SFTP 客户端支持使用! 运行本地操作系统命令的前缀。 因此,您可以在发送之前将文件复制到新名称,然后发送,然后删除副本。

例如:

!cp filename.txt filename122308.txt
put filename122308.txt
!rm filename122308.txt
exit

如果空间很宝贵,请使用 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.:

!cp filename.txt filename122308.txt
put filename122308.txt
!rm filename122308.txt
exit

If space is a premium, use mv twice instead of cp & rm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文