home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / x3270 / unix_files / Examples / child_script.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2005-09-29  |  2.2 KB  |  119 lines

  1. #! /bin/sh
  2. # TSO login script, to be run via the x3270 Script() action.
  3. # sh version
  4.  
  5. set -x
  6. me=`echo $0 | sed 's/.*\///'`
  7.  
  8. # Make sure we're in the right environment.
  9. if [ -z "$X3270INPUT" -o -z "$X3270OUTPUT" ]
  10. then    echo >&2 "$me: must be run via the x3270 Script() action."
  11.     exit 1
  12. fi
  13.  
  14. # Set up login parameters
  15. tcp_host=${1-ibmsys}
  16. dial_user=${2-VTAM}
  17. sna_host=${3-TSO}
  18. userid=${4-USERID}
  19. password=${5-PASSWORD}
  20.  
  21. # Verbose flag for x3270if
  22. v="-v"
  23.  
  24. # Define some handly local functions.
  25.  
  26. # Common x3270 Ascii function
  27. ascii()
  28. {
  29.     x3270if $v 'Ascii('$1')'
  30. }
  31.  
  32. # Common x3270 String function
  33. string()
  34. {
  35.     x3270if $v 'String("'"$@"'")'
  36. }
  37.  
  38. # x3270 cursor column
  39. cursor_col()
  40. {
  41.     x3270if $v -s 10
  42. }
  43.  
  44. # x3270 connection status
  45. cstatus()
  46. {
  47.     x3270if $v -s 4
  48. }
  49.  
  50. # Failure.
  51. die()
  52. {
  53.     x3270if $v "Info(\"$me error: $@\")"
  54.     x3270if $v "CloseScript(1)"
  55.     exit 1
  56. }
  57.  
  58. # Make sure we're connected.
  59. x3270if $v Wait
  60. [ "`cstatus`" = N ] && die "Not connected."
  61.  
  62. # Get to a VM command screen
  63. x3270if $v Enter
  64.  
  65. # Wait for VM's prompt
  66. while [ "`ascii 1,0,5`" != "Enter" ]
  67. do    sleep 2
  68. done
  69.  
  70. # Dial out to VTAM
  71. string "DIAL $dial_user"
  72. x3270if $v Enter
  73. len0=`expr length $dial_user`
  74. sl=`expr 10 + $len0`
  75. dl=`expr 5 + $len0`
  76. while [ "`ascii 0,64,4`" != VTAM ]
  77. do    s="`ascii 8,0,$sl | sed 's/^ *//'`"
  78.     if [ "$s" != "DIALED TO $dial_user" -a "$s" != "" ]
  79.     then    if [ "`ascii 7,0,$dl`" = "DIAL $dial_user" ]
  80.         then    die "Couldn't get to VTAM"
  81.         fi
  82.     fi
  83.     sleep 2
  84. done
  85.  
  86. # Get to the SNA host
  87. string "$sna_host $userid"
  88. x3270if $v Enter
  89.  
  90. # Pass VTAM digestion message and initial blank TSO screen
  91. while [ "`ascii 0,21,20`" = "USS COMMAND HAS BEEN" ]
  92. do    sleep 2
  93. done
  94. while :
  95. do    s="`ascii 0,33,11 | sed 's/^ *//'`"
  96.     [ "$s" != "" ] && break
  97.     sleep 2
  98. done
  99.  
  100. # Now verify the "TSO/E LOGON" screen
  101. [ "$s" = "TSO/E LOGON" ] || die "Couldn't get to TSO logon screen"
  102.  
  103. # Pump in the password
  104. string "$password"
  105. x3270if $v Enter
  106.  
  107. # Now look for "LOGON IN PROGRESS"
  108. len0=`expr length $userid`
  109. nl=`expr 18 + $len0`
  110. [ "`ascii 0,11,$nl`" = "$userid LOGON IN PROGRESS" ] || die "Couldn't log on"
  111.  
  112. # Make sure TSO is waiting for a '***' enter
  113. [ "`cursor_col`" -eq 5 ] || die "Don't understand logon screen"
  114.  
  115. # Off to ISPF
  116. x3270if $v Enter
  117.  
  118. # No need to explicitly call CloseScript -- x3270 will interpret EOF as success.
  119.