IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Executing Linux Shell Script from Mainframe


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
yuvan

New User


Joined: 10 Jan 2006
Posts: 23
Location: India

PostPosted: Fri Jan 17, 2020 4:24 pm
Reply with quote

Hi Team,

Is it possible to execute a Linux script through a mainframe job , We have installed the Coz SFTP installed in our mainframe and SSH also enabled.

I searched through , but could not find any , Please could you tell the possible options.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Sat Jan 18, 2020 12:31 am
Reply with quote

This approach does not use SFTP and I don't think SFTP can run scripts remotely.

Inorder to trigger a Linux script from Mainframe remotely, you would need to have established key based authentication between Mainframe and Linux system.
If you already have public and private keys setup and configured between the systems then its simple.
Code:
//RUNSHEL1 EXEC PGM=BPXBATCH                                           
//STDOUT   DD  SYSOUT=*                                               
//STDERR   DD  SYSOUT=*                                               
//STDPARM  DD  *                                                       
SH ssh -i /pathofkey/rsa_keyname userid@LINUX_IP 'sh -s' < /pathofscript/hello.sh
/*

or

SH ssh -i /pathofkey/rsa_keyname userid@LINUX_IP 'bash -s' < /pathofscript/hello.sh


Where
/pathofkey/rsa_keyname - This is Mainframe USS file location of the private key.
userid - UserID on the Linux machine
LINUX_IP - IP address or name of the linux machine
/pathofscript/hello.sh - This file is present in Mainframe and would be transmitted to the Linux machine and the script would run there.

If you don't have public private keys setup then I can go over it. But will wait for a response.
Back to top
View user's profile Send private message
yuvan

New User


Joined: 10 Jan 2006
Posts: 23
Location: India

PostPosted: Tue Jan 21, 2020 10:40 am
Reply with quote

Not sure SSH key based is setup now .

I just tried with the given JCLs in Dev region , but facing problem in where to add the Linux script /pathofscript/hello.sh .

Tried with the mainframe datasets ,but it says as below.

FSUM7343 cannot open "//XXX.TEST.XXX.JCLS/TESTX" for input: EDC5129I No such file or directory.

Please let us know how to setup if we do not have ssh keys not available.
Back to top
View user's profile Send private message
yuvan

New User


Joined: 10 Jan 2006
Posts: 23
Location: India

PostPosted: Tue Jan 21, 2020 4:29 pm
Reply with quote

Again , I tried with
SH ssh -i /abcusr1/laduser z-kcp-kad@159.15x.xxx.xx 'bash -s' <
/abcusr1/laduser/test.sh

it says

FSUM7343 cannot open "/abcusr1/laduser/test.sh" for input:: EDC5111I Permission denied.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Tue Jan 21, 2020 6:17 pm
Reply with quote

Hello,

The same company that provides Coz SFTP has a product that may be able to do what you need.

//dovetail.com/products/hybridbatch.html

We successfully used this to execute Mainframe SAS programs on Unix servers.

It took us a great deal of time and effort to get it working properly, so I can not just say 'here you go' this is how you should do it.

You will need to contact the company for guidance.

Please note, we 'pay' the company for support. Do not expect them to be diligent with you for free.

I am just directing you to a possible solution.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Wed Jan 22, 2020 4:29 am
Reply with quote

Code:
FSUM7343 cannot open "/abcusr1/laduser/test.sh" for input:: EDC5111I Permission denied.


This says you don't have access to this file. Check the unix file permissions for that file
Back to top
View user's profile Send private message
yuvan

New User


Joined: 10 Jan 2006
Posts: 23
Location: India

PostPosted: Wed Jan 22, 2020 10:29 am
Reply with quote

Now getting below message.

FOTS1273 Warning: Identity file /abcusr1/laduser not accessible: EDC5121I Invalid argument. (errno2=0x055B005B).


FOTS1346 Permission denied, please try again.
FOTS1346 Permission denied, please try again.
FOTS1373 Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).



Actual JCL

//RUNSHEL1 EXEC PGM=BPXBATCH
//STDOUT DD SYSOUT=*
//STDERR DD SYSOUT=*
//STDPARM DD *
SH ssh -i /abcusr1/laduser z-kvc-dev@158.xxx.xxx.xx 'sh -s' <
/abcusr1/test.sh
/*
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Wed Jan 22, 2020 11:30 pm
Reply with quote

Hello,

Code:
FOTS1273 Warning: Identity file /abcusr1/laduser not accessible: EDC5121I Invalid argument. (errno2=0x055B005B).

In your JCL it points to a directory and not a private key file hence the error.

SH ssh -i /pathofkey/rsa_keyname userid@LINUX_IP 'sh -s' < /pathofscript/hello.sh
The text in red above needs to point to a file(not a directory). The file is supposed to contain a private key.

Private key is something that looks like
Code:
-----BEGIN RSA PRIVATE KEY-----                                 
sdfsdfdsfteraj63WF3Jy0CvUsY6mfRqjP53HuRLe5PElFAbQbUcg
MUOcMeZiFxH+K54ZOcxiagcM+h4hjkswdeyZBpxq9mN2YPwd11ddsfsdfsdfY
.
.
.
-----END RSA PRIVATE KEY-----

The private key needs to have a permission of 600. And owned by the user initiating the SSH.

You need to take help from a Unix programmer and Mainframe systems programmer to set the keys up. It would be really hard to set it up without their help.

We members of the forum are happy to help you if you encounter more errors Or if you want to take the easy route, I am up for hire at $100 for the whole setup.
Back to top
View user's profile Send private message
yuvan

New User


Joined: 10 Jan 2006
Posts: 23
Location: India

PostPosted: Mon Jan 27, 2020 11:54 am
Reply with quote

Hi , I am able to run a script with the below option .

//RUNCOZ EXEC PROC=COZPROC,ARGS='unixuserid@111.222.333.4444'
//COZCFGD DD *
//STDIN DD *
uname -norm
date
uptime
pwd
~/scripts/do-tmp-stuff.sh
date
/*
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Tue Jan 28, 2020 2:29 am
Reply with quote

Thanks for posting the solution.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Mainframe openings in Techmahnidra fo... Mainframe Jobs 0
No new posts Mainframe Programmer with CICS Skill... Mainframe Jobs 0
No new posts How to Reformat a file using File Man... All Other Mainframe Topics 14
No new posts executing XCTL command in COBOL witho... CICS 10
No new posts NDM getting stuck - mainframe/JCL All Other Mainframe Topics 13
Search our Forums:

Back to Top