Highlighted
Absent Member.
Absent Member.
952 views

[archive] Thin Client and Shell Script I/O?

[Migrated content. Thread originally posted on 29 July 2005]

We execute many Unix/Linux shell scripts from within our COBOL apps (using C$SYSTEM). We are transitioning to Thin Client and have been unable to find a method to route any shell script-based I/O back through the Thin Client connection.

Has anyone solved this particular issue or know of a workaround?
0 Likes
8 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Thin Client and Shell Script I/O?

There is a very easy way to do what you need.

1. Do the system call and pipe the output of the command to a file
eg CALL "C$SYSTEM" using "acurcl -info > info.txt 2>&1"
2. When the command has finished simply open the text file
read line for line and display in a list box
3. Do a open output on the file to clear the history

Another way is to use pseudo piping which is mentioned in the Acucobol documentation
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Thin Client and Shell Script I/O?

We thought of that for pure script output - but many of these scripts also prompt for and take direct user input. Haven't figured out an 'easy' workaround for that side yet.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Thin Client and Shell Script I/O?

Another easier way to do what Ian suggested is to OPEN INPUT a LINE SEQUENTIAL 'pipe' file.

E.g. Say you want to read the output of a 'ps -ef' command. You can define the file using the following SELECT:

SELECT PS-LISTING.
ASSIGN TO INPUT, "-P ps -ef".

Then after you OPEN INPUT PS-LISTING you can READ each line of the command output and parse it appropriately.

There is no need to remove the file afterward as it only existed as a pipe in memory.

As for the interactive stuff, you could maybe invoke an 'rsh' process on the client itself (i'm new to thin client myself, so I don't know how you do local SYSTEM calls). The old NT resource kit used to include an RSH.EXE, but there are plenty of free ones around.

Hope this helps.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Thin Client and Shell Script I/O?

Originally posted by TimBauer
We thought of that for pure script output - but many of these scripts also prompt for and take direct user input. Haven't figured out an 'easy' workaround for that side yet.

Any input or output to and from the thin client would have to come from the runtime on the server.

One thought would be to write a Cobol program to accept the data needed from the user, then pass it to the shell script on the command line and modify the shell script to look for that information on the command line and get it from there instead of stdin.

For example:

ACCEPT ARG1.
ACCEPT ARG2
ACCEPT ARG3
...
...

CALL "C$SYSTEM" USING "yourscript.sh arg1 arg2 arg3"

(where you use STRING to string together "yourscript.sh" and the values entered for ARG1, ARG2, and ARG3.

Of course, this would only work if you knew ahead of time what the script would prompt for (that is, it is not conditional).

Another option, instead of the command line, would be to see if DuncanK's suggestion of using "-P" allows the file (pipe) to be opened I-O. Then WRITE's to the file would go to stdin and READ's would get the stdout. I forget if Acucobol's pipe support allows that or not.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Thin Client and Shell Script I/O?

I'm in the same boat with Thin Client. I need to interract with HP/UX scripts.

For security puposes we want our users to login to our HP/UX system before being able to run our new GUI menu that I've created to interface to our legacy programs.

I tried a number of ways to execute the UNIX login through our new COBOL menu program but I just can't come up with a way to make it work - the login requires interraction.

My latest attempt was executing this line before accepting the menu screen data:

CALL "C$SYSTEM" USING "login", 73.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Thin Client and Shell Script I/O?

Another option, instead of the command line, would be to see if DuncanK's suggestion of using "-P" allows the file (pipe) to be opened I-O. Then WRITE's to the file would go to stdin and READ's would get the stdout. I forget if Acucobol's pipe support allows that or not.


Sorry. Been there, done that. Pipe files can only be opened INPUT or OUTPUT. 😞

But we have done what you suggested. We use the Cobol to ask the user for the arguments (including any conditional code) and then pass them onto the script. We haven't found any instances we can't get around using this method.

In fact, I'm just working on another one that prompts the user for a file name then OPENs INPUT the following pipe:
'-P echo "\$sendfile xxxxxx\nbye' | ftp host_name'
Where 'xxxxx' is the filename they have specified, and 'sendfile' is a macro defined in the '.netrc' file for that host. This way I can parse the output from the 'ftp' command to look for the 3-digit numeric message numbers that it displays.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Thin Client and Shell Script I/O?

Originally posted by Heli-pP6989
For security puposes we want our users to login to our HP/UX system before being able to run our new GUI menu that I've created to interface to our legacy programs.

I once did something with this on a project.

I wrote a C function and compiled it into the Unix Acucobol runtime via sub.c that took a Unix login and password as parameters and verified that they were valid.

The menu program asked for a login and password and then called this C function (via CALL). Even though the thin client was running on Windows, the CALL would execute in the runtime on Unix and therefore have access to the Unix password database. The call returned a status as to whether or not the login and password were valid.

I don't have an example of that code with me right now - if I have time, I will try to dig it up. But here is an example I found on the newsgroups:


/*
* Verify user account and password in the protected password database.
*/
int check_user(char *user, char *passwd)
{
   char *namep;
   struct pr_passwd *ppwd;
   struct passwd *pwd;
   extern char *crypt(const char *, const char *);
   extern char *bigcrypt(char *, char *);
   extern struct passwd *getpwnam(const char *);
   extern struct pr_passwd *getprpwnam(char *);

   pwd = getpwnam(user);
   ppwd = getprpwnam(user);


   if (!pwd) {
      (void) fprintf(stderr,"user '%s' does not exist\n",user);
      return(1);
   }


#ifdef CRYPT
   namep = crypt(passwd, ppwd->ufld.fd_encrypt);
#endif


#ifdef BIGCRYPT
   namep = bigcrypt(passwd, ppwd->ufld.fd_encrypt);
#endif


   (void) printf("Password=%s Crypt=%s System=%s\n",
          passwd,namep,ppwd->ufld.fd_enc_rypt);


   if (strcmp(namep, ppwd->ufld.fd_encrypt)) {
      (void) fprintf(stderr,"Invalid Password for '%s':'%s'\n",user,passwd);
      return(2);
   }
   /* (void) printf("\nPassword matches\n"); */
   return(0);
   /* NOTREACHED */

}
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Thin Client and Shell Script I/O?

Thanks for the info Joe.

Although my programming skills in any flavor of C are very weak I did realize from your example that if my COBOL program could create a sequential file consisting of username/password (and a delimiter of : ) that was input by the users I could do this in a UNIX script.

After calling the script using C$SYSTEM I could test the results in the COBOL program by reading the results in the file.

I tested it and it worked......this is the code:

inputfile=name_password #Created by the COBOL program
typeset -L2 seed
passwd=/etc/passwd

# Check if input file exists
if [[ ! -r "$inputfile" ]]; then
print "You Must login to procede "> name_password
exit 1
fi
# Check that login name is correct
grep "^$name:" $passwd
if [[ $? -ne 0 ]]; then
print "Incorrect login name - $name not in the password file">name_password
exit 1
fi


name=`cat name_password| cut -d : -f 1`
password=`cat name_password| cut -d : -f 2`
filepassword=`grep "^$name:" $passwd| cut -d : -f 2`
seed=$filepassword
inputfile=name_password


encrypt=` { echo "${password}\c"
sleep 1
echo "${seed}\c"; } \
| /usr/lib/makekey `

if [[ $encrypt != $filepassword ]]
then
print "You did NOT key in the correct password "> name_password
else
rm name_password #login successful get rid of the evidence
fi
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.