batching qsh sftp fails when using a variable for script

35 pts.
Tags:
AS400 iseries
iSeries Commands
Hi all !

this works -

SBMJOB CMD(QSH CMD('/QOpenSys/usr/bin/sftp -v -b  +                        /home/account/sftpcmd.txt +                               remote_user_account'))              +                                    JOB(SSHJOB) USER(WIRM5501)

this does not

SBMJOB CMD(QSH CMD( &CMDSHL ))   JOB(SSHJOB) USER(WIRM5501)

where &CMDSHL is the exact quoted command in the working script

I get this error

qsh: 001-0014 Command /QOpenSys/usr/bin/sftp -v -b /home/... not found

I've set these

QIBM_USE_DESCRIPTOR_STDIO and QIBM_QSH_CMD_ESCAPE_MSG

 

anyone ever made this work, or know why it's failing?

 

thanks,

Michael



Software/Hardware used:
iSeries as400

Answer Wiki

Thanks. We'll let you know when a new response is added.

Check the variable &CMDSHL just before it gets submitted.
Do you have the Quote marks at the beginning and end of the variable?

Discuss This Question: 13  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • BDLmichael
    I used triple single quotes at each end to build the variable, and when in debug I see the single quotes in the variable contents Michael
    35 pointsBadges:
    report
  • CharlieBrowne
    When you are in debug, have you tried to do a cut & paste. doin the the past on a command line to see if you get more detail info on the error?
    41,380 pointsBadges:
    report
  • TomLiotta
    ...where &CMDSHL is the exact quoted command in the working script If it really was the "exact quoted command", I would expect it to fail. But I also exact that it's not "exact". For example, you probably shouldn't have "+" signs in there. That is, it's almost certain that you aren't showing us what's actually in &CMDSHL. Instead, you're describing it to us. It's practically guaranteed that there is a difference that isn't being shown. If you can use debug to see the value, copy/paste from the debug session into Notepad. Then copy/paste from Notepad into a {code} block back here. By going through Notepad, you'll be able to capture CR/LFs that don't exist when you copy from a workstation screen. When you post in a {code} block, the result won't get the usual compression of blanks that HTML gives. We'll see more or less exactly what you see. Tom
    125,585 pointsBadges:
    report
  • BDLmichael
    Hi again - the CL command is CHGVAR &CMDSHL ('''/QOpenSys/usr/bin/sftp -v -b + /home/WIRM123/sftpcmd.txt wirm123@sftp2.123''') using three single quotes the string from the debug session is as below ( 200 type character string ) '/QOpenSys/usr/bin/sftp -v -b /home/WIRM123/sftpcmd.txt wirm123@sftp2.123' the CL code to execute ( and fails) is SBMJOB CMD(QSH CMD( &CMDSHL )) JOB(SSHJOB) USER(WIRM123) the sftpcmd.txt is is a simple text file cd Share/5501/test/5501updt ls put MGG1.TXT MGG1.TXT ls exit this all works when I make the hardcoded call as below SBMJOB CMD(QSH CMD('/QOpenSys/usr/bin/sftp -v -b + /home/WIRM123/sftpcmd.txt + wirm123@sftp2.123')) + JOB(SSHJOB) USER(WIRM5501) but I want to be able to provide different directories and such as this is in a generic CL intersting problem - but I've reached the end of my skills as far as what to be able to test.
    35 pointsBadges:
    report
  • TomLiotta
    ...using three single quotes... Why would you put three quotes there? I've never tested it, but what happens when you put quotes around a command on a QSH command line? If I try this:
    ===> 'ls /home/toml'
    ...to list my /home directory in a QSH session, I get this error:
    • qsh: 001-0014 Command ls /home/toml not found.
    QSH thinks that the entire quoted string is the name of the command. Your &CMDSHL value should probably only have single quotes. Tom
    125,585 pointsBadges:
    report
  • wpoulin
    This can work, I have a similar job that runs thru the Job Scheduler, Here is a snippet of the code, maybe an example will help, ZFTP is a command that executes a CL by the same name; ZSFTP HOST(***.nh.gov) SCRIPT('/tmp/lowmo') + USER('******') PGM PARM(&HOST &SCRIPT &USER) DCL VAR(&HOST) TYPE(*CHAR) LEN(15) DCL VAR(&SCRIPT) TYPE(*CHAR) LEN(15) DCL VAR(&USER) TYPE(*CHAR) LEN(15) DCL VAR(&CMD) TYPE(*CHAR) LEN(500) ADDENVVAR ENVVAR(SFTP_USER) VALUE(&USER) REPLACE(*YES) ADDENVVAR ENVVAR(SFTP_HOST) VALUE(&HOST) REPLACE(*YES) CHGVAR VAR(&CMD) + VALUE('PATH=$PATH:/QOpenSys/usr/bin && + sftp -b' *BCAT &SCRIPT *TCAT '.sftp + $SFTP_USER@$SFTP_HOST 22') QSH CMD(&CMD) Again this is run in batch thru the Job Scheduler. There is more code, but I didn't think it related to executing QSH in batch and with a variable. Hope this helps, Bill Poulin
    2,480 pointsBadges:
    report
  • wpoulin
    It should be ZSFTP is the command. Bill
    2,480 pointsBadges:
    report
  • TomLiotta
    ...I didn’t think it related to executing QSH in batch and with a variable. It's definitely related when extra quotes are added that shouldn't be there. But the idea of using a literal or a variable is sound. Just don't put quotes in the variable that aren't present in the literal. Tom
    125,585 pointsBadges:
    report
  • mmanley
    You probably need to trim the string, and append a X'00' to the end. This command expects a null terminated parameter
    90 pointsBadges:
    report
  • TomLiotta
    This command expects a null terminated parameter It's already known that a null-terminator is not needed. The QSH command works fine without one as demonstrated by the OP's working example. The issue is in the difference between using a literal for the QSH command parameter and a variable. Because QSH is a system command, it has no need for a null-terminator. Tom
    125,585 pointsBadges:
    report
  • wpoulin
    Tom, You took my statement out of context. My full statement was; There is more code, but I didn’t think it related to executing QSH in batch and with a variable. Thank You, Bill Poulin
    2,480 pointsBadges:
    report
  • TomLiotta
    There is more code, but... Ah. Not exactly out of context, just misinterpreted by me. Now I see the alternative interpretation. In that case, there's no need for my related comment. Tom
    125,585 pointsBadges:
    report
  • BDLmichael
    [...] 4. Several community members come together as they try to solve BDLmichael’s problem solving a iSeries command error. [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following