views:

1788

answers:

7

I'm sending a file from a mainframe host 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.

A: 

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
!
dacracot
The commands are being sent via JCL control card. I don't think this approach will work.
+1  A: 

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

How are you submitting the commands in JCL? Are you executing a shell command from the JCL via the BPX* commands?
Nighthawk
+1  A: 

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.

JimB
A: 

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.

skoob
A: 
#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"
Tom
A: 

Tom and sth, thank you so very much! Works perfectly for me.

fonji
A: 

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.

Don Rice