ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

CL + SFTP + FILE NAME = confused!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CL + SFTP + FILE NAME = confused!

    Hi, all,

    I managed to figure out SFTP with the help of Mr. Scott Klement's articles and a network engineer here who knows UNIX commands, but I do have a question.

    Is it possible to use a CL variable when I name the file? Below, where I have in/replace.csv, I really want in/VARIABLENAME.csv because they want the time stamp included on the file name. I get the feeling that isn't possible... but before I tell my business users that, I want to be sure. Has anyone done something similar?

    Has anyone ever seen any good CL examples of various commands to be used with QSH?

    Thank you so much for your time!


    PHP Code:
        CHGVAR     VAR(&CMD) +                                          
             
    VALUE('PATH=$PATH:/QOpenSys/usr/bin  &&  +                 
             echo "put /home/sftpad/sharedfiles/replace +               
             in/replace.csv" | sftp -P 990 +                            
             USER@00.000.000.000'
    )                               

          
    QSH CMD(&CMD

  • #2
    Unless I'm missing something, I would think it would simply be a matter of concatenating the variable name in the string.

    Code:
    CHGVAR    VAR(&FILE) VALUE('replace' *CAT &TIME *CAT '.csv')
    CHGVAR    VAR(&CMD) +
         VALUE('PATH=$PATH:/QOpenSys/usr/bin  &&  +
         echo "put /home/sftpad/sharedfiles/replace +
         in/' *CAT &FILE &TCAT '" | sftp -P 990 +
         USER@00.000.000.000')
    
    QSH CMD(&CMD)

    Comment


    • MelissaG
      MelissaG commented
      Editing a comment
      D'oh! Sometimes I just don't see what is right in front of my face. Thank you, Brian!

  • #3
    I'm going to tag on to my own post here... I have more SFTP questions than you can shake a stick at. In this code, I retrieve the file, copy it from the IFS file to a "flat" file and then remove the file from the external server. It doesn't work when my CL runs, BUT the next morning, I can run the same CL and it deletes the file.

    Since I don't really understand the commands, I get the feeling that I either need to end the session and restart it (??? that seems weird) or I have too much stuff in the second command. No one here knows this. Can anyone see anything wrong with what I have? (IP address, user and file names have been changed to nonsense).

    RFTM2DBF is a Trailblazer command - we have that tool in house, but not the license to use SFTP (at least not right now).

    Any hints or thoughts about this will be (once again!) greatly appreciated.



    PHP Code:
               RFMT2DBF   IFSFILE(RECEIVED) +                                          
                            
    PATH('/home/userid/sharedfiles') +                         
                            
    TOFILE(filenameREPLACE(*YES)                             


          
    SNDMSG  MSG('About to attempt delete'TOUSR(*SYSOPR)                        

         
    /****************************************/                                    
          /* only delete for production*/                                              
         /****************************************/                                    
               
    IF         COND(&ENV *EQ 'P'THEN(DO)                                  
               
    ADDENVVAR  ENVVAR(QIBM_QSH_CMD_OUTPUT) +                                
                            
    VALUE('FILEAPPEND=/tmp/IR1501DEL.log') +                   
                            
    REPLACE(*YES)                                              
               
    ADDENVVAR  ENVVAR(QIBM_QSH_CMD_ESCAPE_MSGVALUE(Y) +                   
                            
    REPLACE(*YES)                                              
           
    /* delete the file from the server */                                       
               
    CHGVAR     VAR(&CMD) +                                                  
                    
    VALUE('PATH=$PATH:/QOpenSys/usr/bin  && +                          
                 echo "rm out/filename.txt"  +                                          
                                    | sftp -P 990 +                     
                   masterbrand@00.000.000.000'

    Comment


    • #4
      No errors in the log you're creating in /tmp?

      You say something about having too much stuff in the second command, not sure what that means, as far as I can tell you have one command (rm out/filename.txt), so it's dead simple.

      Comment


      • #5
        Scott, thank you for replying.

        I'm not getting any errors in the log in /tmp.

        What's really odd is that when I run exactly the same program the next morning, the RM works. My supervisor was wondering if there is something that is "holding" the file I'm trying to delete? For example, do I need to "end" the previous sftp command somehow before I attempt it again? The previous command is almost exactly like the 'rm' command except that it's a "get".



        PHP Code:
             /*start INC0220894 */                                                         
              
        CHGVAR     VAR(&CMD) +                                                       
                           
        VALUE('PATH=$PATH:/QOpenSys/usr/bin      &&    +                
                      echo "get out/filename.txt +                                          
                           /home/userid/sharedfiles/received" | sftp -P 990 +              
                           masterbrand@00.000.000.000'
        )                                    
             
        /*end INC0220894 */                                                           

              
        ADDENVVAR  ENVVAR(QIBM_QSH_CMD_OUTPUT) +                                     
                           
        VALUE('FILEAPPEND=/tmp/IR1501RCVLog.txt') +                     
                           
        REPLACE(*YES)                                                   
              
        ADDENVVAR  ENVVAR(QIBM_QSH_CMD_ESCAPE_MSGVALUE(Y) +                        
                           
        REPLACE(*YES)                                                   

               
        QSH CMD(&CMD)                                                               
               
        MONMSG MSGID(QSH0000EXEC(DO)                                              
              
        SNDMSG     MSG('Receipt File transfer failed!'TOUSR(*SYSOPR)               
              
        ENDDO                                                                        
            ENDDO 

        Thank you, again. I appreciate it.

        Comment


        • #6
          The previous command will have ended before the 'QSH' command returns control to your CL program. Unless these are running in separate jobs? (or separate threads, I guess.)

          It could be that something on the SFTP server is using the file, still... But, on a typical Unix system, you could still delete the file in that case, and it would no longer be visible (but would still be on disk, invisible, until the server-side job was finished with it.)

          I would suggest talking to whomever runs the SFTP server. Tell them you're running 'rm' to delete the file and getting no errors, but the file is still there. Yet, if you run it later, it seems to work fine. Maybe they'd know why, or have logs they can check in.

          Comment


          • #7
            thank you again - that's the kind of muscle I needed to go back to the server people and ask for help.

            Comment


            • #8
              So, all this time I thought my code was wrong ... it turns out that the person who set up the scheduler had the parameters backward. The job was running, because it runs almost identically in Production and in Test, BUT it only deletes the file in Production. When I was running it manually, I sent the correct parameter list.

              Now, once the dent in my head has healed (from banging my head on my desk), I can move on to the next problem!

              Thank you.

              Comment

              Working...
              X