• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 880
  • Last Modified:

Bash help for telneting to AS400

Trying to automate a program that needs to be ran on our AS400. The script is fairly bland and simple, yet i cannot get it to work completely. It logs in just fine, but needs to run one step prior to calling the PGM. I've searched for other answers to this but i cant seem to get them to work correctly. The steps are as follows:

telnet as400
CALL PGM(program)

The code I am using is below. This is my first question so I am not too sure what other information anyone would need. In my script i DID have variables used for $user and $pass but had issues logging in, so using (send "username") seemed to atleast get me logged into the system.

The script fails on the F3 command. I am not too familiar with the tput command. Are there other options? When the script fails to send a 'F3', it tries to send the CALL PGM instead and then it fails sending me back to my prompt.

Thanks in advance.
/usr/bin/expect -  << END
spawn /usr/bin/telnet
expect "User*"
send "username"
send "\t"
send "pass"
send "\r"
sleep 5
exec tput kf3
send "CALL PGM(program)\n"
send "SIGNOFF\n"
expect eof

Open in new window

1 Solution
yanceyitAuthor Commented:
This how-to was found write after i posted my question. The TPUT command i got from google to place a F3 in the script was incorrect. Once I followed the following, the script worked fine. For anyone else having these issues:
1.	start od with the -c option 
2.	press the function key 
3.	press the return key 
4.	press ^D 
Here's what it looks like when I do that to find out what my F1 key generates:
    % od -c
    0000000 033   [   1   1   ~  \n
The string between the 0000000 and \n is what we want. You can translate that into a send command like this one:
    send "\033\[11~"

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now