3

sftp を使用して、メインフレーム ホストから Linux ftp サーバーにファイルを送信しています。

ファイルがLinuxボックスに存在したら、ファイル名に日付を追加したいと思います。(例: filename.txt は filename122308.txt になります)

「date +%m%d%y」を使用して「rename」コマンドを試しました - ファイルの名前は変更されましたが、フラグは実行されませんでした (ファイル名は filename'date +%m%d%y'.txt になりました

「cp」および「mv」コマンドが機能しません...何かアイデアはありますか?

ありがとう。

4

6 に答える 6

1

datesftp はシェルを実行していないため、コマンドを実行するものは何もありません。おそらく、送信者側で必要な新しい名前を評価してから、sftp rename を実行する必要があります。

もう 1 つのオプションは、ファイルをキュー エリア (日付文字列を含むフォルダーなど) に送信し、それに応じて受信したファイルを移動/名前変更する Linux ボックスのスクリプトを作成することです。

于 2008-12-23T19:38:46.727 に答える
1

コマンドは、JCL 制御カードを介して送信されています。このアプローチはうまくいかないと思います。

于 2008-12-23T17:15:32.070 に答える
0
#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"                                          
于 2009-09-21T17:34:33.200 に答える
0

Linux サーバーにアクセスできますか? その場合、そこにあるファイルの名前を変更するだけです。たとえば、inotify を使用してディレクトリを監視し、そのディレクトリに新しいファイルが作成されるたびにファイルに日付を追加するスクリプトを作成できます。

Pythonでの簡単な例を次に示します (ただし、ほとんどの言語には inotify バインディングがあります)。リッスンするイベントは IN_CREATE です。

于 2008-12-24T09:40:37.557 に答える
0

メインフレームの SFTP クライアントについてはわかりませんが、多くの SFTP クライアントは ! プレフィックスを使用して、ローカル オペレーティング システム コマンドを実行します。したがって、送信する前にファイルを新しい名前にコピーし、送信してからコピーを削除できます。

例えば:

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

スペースが重要な場合は、cp と rm の代わりに mv を 2 回使用します。

于 2010-08-10T00:06:57.157 に答える
0

コマンドラインからできますか?sftp を次のように実行するためのオプションが存在します...

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

...だからあなたは実行するかもしれません...

export WHEN=`date +%m%d%y`
sftp theUser@theHost:filename$WHEN.txt filename.txt <<-!
thePassword
!
于 2008-12-23T17:10:56.307 に答える