Automic Workload Automation

 View Only
  • 1.  UNIX JOBS SFTP commands

    Posted Mar 19, 2020 03:18 PM
    Hello,

    I am on v12.3 and am trying to create a UNIX JOBS that makes an SFTP connection and moves files from the agent UNIX server to a Windows server.

    UNIX page Shell Script
    In The Process page
    sftp -v -o IdentityFile=/home/automic_svc/.ssh/id_rsa -o PasswordAuthentication=no CDLE_UI_UFACTS_UIM_Key@xx.xx.xx.xx
    cd /inbound
    lcd /ifile/workfiles
    put QN.P.INTERNET.BKP.LADT.SREPORT*
    exit

    The job makes the connection but it won't accept the commands.  It still thinks it's on the agent server and any commands that are not Linux are not recognized.  The job report shows the connection but no sftp prompt.  When I run this from the command line on the agent server it works fine from the sftp prompt.  

    I've looked at the documentation and I don't see anything that says I can or can't do this.  But command line seems to be limited to the UNIX tab in which case it doesn't run anything in the Process area.

    Is this a case of I have to create a shell script with the commands and execute it with Automic?  Or is there a way to make this work from within the JOBS?

    Thanks

    ------------------------------
    Developer
    State of Colorado
    ------------------------------


  • 2.  RE: UNIX JOBS SFTP commands

    Posted Mar 19, 2020 07:27 PM
    Edited by Reed Byers Mar 19, 2020 07:30 PM
    I think what you're looking for here, is called a "HERE DOC" in UNIX.

    My example is in BASH (can't swear by other shells), but what you want is:

    sftp -v -o IdentityFile=/home/automic_svc/.ssh/id_rsa -o PasswordAuthentication=[skipped]  << EOF
    cd /inbound
    lcd /ifile/workfiles
    put QN.P.INTERNET.BKP.LADT.SREPORT*
    EOF

    The "<< EOF" at the end of the SFTP line means, "read input from this script, until you reach the EOF label".  EOF can be any label you like.

    When it reaches the EOF label at the end (which would otherwise be interpreted as another command), it says "OK done", ends SFTP and proceeds with further shell scripting.

    Hope this helps!  :)

    ------------------------------
    Reed Byers
    Programmer/Analyst
    Oregon State University
    ------------------------------



  • 3.  RE: UNIX JOBS SFTP commands
    Best Answer

    Posted Mar 23, 2020 10:12 AM

    This.

    You can't just put the commands for sftp underneath the sftp command, you need to pipe them to the sftp program.

    Without having tried which ones's work for sftp and which don't, here's some ways to do it:

    1. the "here document" as shown
    2. echo "cd /inbound ; lcd /ifile/workfiles" | sftp -v -o (...)
    3. The -b flag to sftp:

     -b batchfile
                 Batch mode reads a series of commands from an input batchfile
                 instead of stdin.

    As for number two, not sure if semicolon works or possibly echo -e and then using "\n" in it's place

    But the simplest option is likely number 3. Put your commands into a file and feed that file to sftp as a commands file. You can even do this dynamically from Automic if needed, like so:

    echo "cd /inbound" > /tmp/cmdfile
    echo "lcd /ifile/workfiles" >> /tmp/cmdfile
    (and so on)

    See "man sftp" for the options you have, but "-b" has been there since pretty much forever for the bsd-derived sftp.

    hth





  • 4.  RE: UNIX JOBS SFTP commands

    Posted Mar 24, 2020 02:56 PM
    Thanks Carsten.  I did not try this in the process tab but added it to my batch script.  It worked well.

    echo put /ifile/workfiles/$sourceFile $newFile >> files.txt
    sftp -o IdentityFile=~/.ssh/id_rsa -b files.txt.....

    ------------------------------
    Developer
    State of Colorado
    ------------------------------



  • 5.  RE: UNIX JOBS SFTP commands

    Posted Mar 24, 2020 02:51 PM
    Thanks Reed.  My team decided that writing a bash script would work best and execute from Automic and it did.  But I still want to issue commands directly from the process tab.  I will re-write in my sandbox and see if it works.

    ------------------------------
    Developer
    State of Colorado
    ------------------------------



  • 6.  RE: UNIX JOBS SFTP commands

    Posted Mar 25, 2020 02:02 PM
    Edited by Reed Byers Mar 25, 2020 02:03 PM

    As long as the Process tab is on a UNIX job, using the BASH shell, it should work the same.


    [My group only gets in trouble when we try to include BASH in a workflow Process tab.]  :)

    I prefer the HERE DOC solution, because it doesn't create a junk file on the file system, and I think it's easier to read than piping.

    But however you solve it, your problem was definitely shell-centric rather than an issue in AWA.


    Best wishes...



    ------------------------------
    Reed Byers
    Programmer/Analyst
    Oregon State University
    ------------------------------