OpenVMS - Trying to create an action for invalid selection - openvms

I'm trying to write a simple .com file that will give the user a choice to open files from a pick list. It opens the files fine when you select the number, but if you select an invalid choice, it should loop you back to the pick list. That is not working.
I've been looking at the OpenVMS User's Manual but have been unable to resolve this.
$! CHOICE.COM
$! Test file to offer choice to open one of two files
$!
$ ON WARING THEN EXIT
$ HOME:
$ WRITE SYS$OUTPUT “”
$ WRITE SYS$OUTPUT “1 – FILEA”
$ WRITE SYS$OUTPUT “2 – FILEZ”
$ WRITE SYS$OUTPUT “”
$ WRITE SYS$OUTPUT “”
$ INQUIRE P1 “Enter the number of the file to open or type X to exit:”
$ IF P1.EQS.”1”
$ THEN
$ #FILEA.COM
$ ENDIF
$ IF P1.EQS.”2”
$ THEN
$ #FILEZ.COM
$ ENDIF
$ IF P1.EQS.”X”
$ THEN
$ EXIT
$ IF P1.EQS.””
$ THEN
$ WRITE SYS$OUTPUT “Invalid Choice – try again!”
$ WAIT 0:0:5
$ GOTO HOME
$ ENDIF
$ !
I expect an invalid choice to return the user to HOME:

OK, with a little help from a programmer, I have the answer.
$! CHOICE.COM
$! Test file to offer choice to open one of two files
$!
$ ON WARING THEN EXIT
$ HOME:
$ WRITE SYS$OUTPUT ""
$ WRITE SYS$OUTPUT "1 - FILEA"
$ WRITE SYS$OUTPUT "2 - FILEZ"
$ WRITE SYS$OUTPUT ""
$ WRITE SYS$OUTPUT ""
$ INQUIRE P1 "Enter the number of the file to open or type X to exit:"
$ IF P1.EQS."1"
$ THEN
$ #FILEA
$ EXIT
$ ENDIF
$ IF P1.EQS."2"
$ THEN
$ #FILEZ
$ EXIT
$ ENDIF
$ IF P1.EQS."X" THEN EXIT
$ WRITE SYS$OUTPUT "Invalid Choice - try again!"
$ WAIT 0:0:5
$ GOTO HOME

Related

Linux simple while loop

I have log file keep updating for 30 minutes and I implement script which will check that log file till it has "success" message written in it.So far I have implemented below.Any help or correction would be appreciated.
while [ "($cat R12TECH2.log | grep 'success')" != " " ]
do
echo "Please wait...devccm Adautoconfig is still running..."
sleep 5
done
echo "Status of devccm adautoconfig"
cat R12TECH2.log | grep 'success'
exit
Replace
while [ "($cat R12TECH2.log | grep 'success')" != " " ]
With:
while ! grep -q 'success' R12TECH2.log
The while statement does not require a [...] statement. It will work with any command that provides a satisfactory exit code. grep is one such command. Since we don't care about the output of the grep command, we use -q to silence it.
Grep and exit codes
Consider the test file:
$ cat R12TECH2.log
line 1
success
line 3
This grep command returns success (0):
$ grep -q 'success' R12TECH2.log; echo code=$?
code=0
We, however, want the while loop to run only if success is not in the file. Thus, provide a leading ! which tells the shell to negate the exit code:
$ ! grep -q 'success' R12TECH2.log; echo code=$?
code=1

Handling DCL ON ERROR actions after first error?

The OpenVMS DCL command HELP ON EXAMPLE displays:
ON
Examples
1.$ ON SEVERE_ERROR THEN CONTINUE
A command procedure that contains this statement continues
to execute normally when a warning or error occurs during
execution. When a severe error occurs, the ON statement signals
the procedure to execute the next statement anyway. Once
the statement has been executed as a result of the severe
error condition, the default action (ON ERROR THEN EXIT) is
reinstated.
According to the help if neither [-]x.for nor [-]y.for exist then the last two lines will not be executed:
$ on error then $ continue
$ rename [-]x.for []
$ rename [-]y.for []
$ type *.for
Is there a way to set the ON ERROR handling as in the first line w/o placing an ON ERROR statement between each line of the script?
If the ON ERROR fires, you have to re-establish it. It looks like you
don't know whether any of the files exists. So the ON ERROR needs to be
re-established after the first failing command.
You can do this in a subroutine, like in:
$ on error then $ gosub on_error
$ rename [-]x.for []
$ rename [-]y.for []
$ on error then $ exit
$ type *.for
$ exit
$
$ on_error:
$ on error then $ gosub on_error
$ return
Also, you can handle this differently, with disabling error checking (SET
NOON):
$ set noon
$ rename [-]x.for []
$ rename [-]y.for []
$ set on
$ type *.for
or establishing error handling only for sever errors (ON SEVERE_ERROR):
$ on severe_error then $ exit
$ rename [-]x.for []
$ rename [-]y.for []
$ on error then $ exit
$ type *.for

Openldap how to use RFC2307AIX schema which support aixAuxAccount objectClass

I'm setting up an Openldap system with two machines, include one Openldap Server (Redhat 6.4) and one Openldap Client (AIX 6.1)
Now I could create LDAP User and login in AIX machine with that account.
However, I want to use hostsdeniedlogin and hostsallowedlogin those are two attributes of objectClass aixauxaccount but my Openldap server doesn't have any Object like that.
I found an aix2307aix.schema on internet, but don't know how to use it.
rfc2307aix.schema
Beside that file, I also found: a file names nisSchema.ldif which have content in the following form:
dn:cn=schema
changetype: modify
replace: objectclasses
objectclasses: (
1.3.18.0.2.6.472
NAME 'aixAuxAccount'
DESC 'Auxiliary AIX user information objectclass, for use with posixaccount an
d shadowaccount objectclasses'
SUP top
AUXILIARY
MAY ( passwordChar $ adminGroupNames $ aIXDefaultMACLevel $ aIXFuncMode $ aIXi
sDCEExport $ aIXLowMACLevel $ aIXPromptMAC $ aIXScreens $ aIXUpperMACLevel $ aud
itClasses $ authMethod1 $ authMethod2 $ coreSizeLimit $ coreSizeLimitHard $ cPuS
ize $ cPuSizeHard $ dataSegSize $ dataSegSizeHard $ filePermMask $ fileSizeLimit
$ fileSizeLimitHard $ groupList $ groupSwitchUserAllowed $ hostLastLogin $ host
LastUnsuccessfulLogin $ hostsAllowedLogin $ hostsDeniedLogin $ isAdministrator $
isAccountEnabled $ isDaemon $ isLoginAllowed $ isRemoteAccessAllowed $ isSwitch
UserAllowed $ ixTimeLastLogin $ ixTimeLastUnsuccessfulLogin $ loginTimes $ maxFa
iledLogins $ maxLogin $ openFileLimit $ openFileLimitHard $ passwordCheckMethods
$ passwordDictFiles $ passwordExpireTime $ passwordHistSize $ passwordMaxRepeat
edChars $ passwordMinAlphaChars $ passwordMinDiffChars $ passwordMinLength $ pas
swordMinOtherChars $ physicalMemLimit $ physicalMemLimitHard $ roleList $ StackS
izeLimit $ StackSizeLimitHard $ SystemEnvironment $ terminalAccess $ terminalLas
tLogin $ terminalLastUnsuccessfulLogin $ timeExpiredLogout $ timeExpireLockout $
trustedPathStatus $ unsuccessfulLoginCount $ userEnvironment $ passwordFlags )
)
And I just found the way to add the rfc2307aix.schema file as the following link
how-to-add-a-new-schema-to-openldap
that schema seem to be added successfully, but I stuck with that nisSchema.ldif file found on AIX.
I attempted to use ldapadd, but not successful.
modifying entry "cn=schema,cn=config"
ldap_modify: Other (e.g., implementation specific) error (80)
Anyone know how to deal with this, please help!
I already had that "aixAuxAccount" ObjectClass. My AIX Client working fine now with 'hostsdeniedlogin' attribute. I had to clear the client cache and reconnect the Ldap Admin Tool to see the change. And don't need to use the nisSchema.ldif
For those, who dont know how to use the rfc2307aix.schema, please follow this thread:
how-to-add-a-new-schema-to-openldap
Thank you, for your attention and helps.

Hard time with scripting in OpenVMS

I am having a very hard time with scripting in OpenVMS
I have a certain output in a file called test.txt .For example :
[WWEWE#http-lx-as code]$ cat test.txt
** Configuration for file "MULTINET:NETWORK_DEVICES.CONFIGURATION" **
Device Adapter CSR Address Flags/Vector
------ ------- ----------- ------------
se0 (Shared VAX/VMS Ethernet) -NONE- -NONE- -NONE-
s10 (Serial Line IP) -NONE- -NONE- -NONE-
dn0 (IP over DECNet link) -NONE- -NONE- -NONE-
I have written a script in Linux which helps to pick up all the information under the device column in this case se0,s10,dn0.
Can we do a similar thing in OPEN VMS
The Linux script is as follows :
SCRIPT :
for i in `cat test.txt 2>/dev/null |egrep '^[a-z]' |grep -v '\*\*' | awk '{print $1}'`
> do
> echo Begin-interface: $i
> done
OUTPUT :
Begin-interface: se0
Begin-interface: s10
Begin-interface: dn0
Let me know if it can be achieved,
Thanking you in advance
Assuming that you need anything in the first column below the line starting with '-'
you can try the following in a command file, e.g. extract_if.com
$ IF P1 .EQS. "" THEN GOTO nothing_specified
$ IF F$SEARCH( P1 ) .EQS. "" THEN GOTO file_not_found
$ parse_line = 0
$ OPEN/READ/ERROR=file_open_error infile 'P1'
$read_loop:
$ READ/ERROR=file_read_error/END_OF_FILE=end_of_file infile inline
$ IF F$LENGTH( F$EDIT( inline, "TRIM" ) ) .EQ. 0 THEN GOTO read_loop
$ IF parse_line .EQ. 1
$ THEN
$ interface = F$ELEMENT( 0, " ", F$EDIT( inline, "TRIM,COMPRESS" ) )
$ WRITE SYS$OUTPUT F$FAO( "Begin-interface: !AS", interface )
$ ELSE
$ parse_line = ( F$EXTRACT( 0,1,inline ) .EQS. "-" )
$ ENDIF
$ GOTO read_loop
$nothing_specified:
$ WRITE SYS$OUTPUT "No file specified"
$ GOTO finished
$file_not_found:
$ WRITE SYS$OUTPUT F$FAO( "File !AS not found", P1 )
$ GOTO finished
$file_open_error:
$ WRITE SYS$OUTPUT F$FAO( "Error opening file !AS", P1 )
$ GOTO finished
$file_read_error:
$ WRITE SYS$OUTPUT F$FAO( "Error reading from file !AS", P1 )
$ GOTO close_file
$end_of_file:
$close_file:
$ IF F$TRNLNM("infile").NES."" THEN CLOSE infile
$finished:
$ EXIT
Run this script using:
$ #extract_if test.txt
The output should be as specified.
It seems you are familiar with AWK. You can also install GAWK for OpenVMS.
Two years late....
$ gawk/comm="/^[a-z]/{print ""Begin-interface:"",$1}" test.tmp
Begin-interface: se0
Begin-interface: s10
Begin-interface: dn0
Guess I will never understand those Unix script weenies which think they need 4 or 5 piped commands, then the proper tool and do everything in one step.
Piping 'cat' output into awk or perl is the most obvious and obnoxious sign of clueless-ness.
Oh well... Onwards!
Hein.

Whats wrong with this C shell script?

I am trying to write a C shell equivalent script for the bash script mentioned here.
This is what I have :
#! /bin/tcsh
set now=`date +%Y%m%d%H%M.%S`
if (( ! -f "./cache" ) || (-n "`find ./monme -newer ./cache`" ))
then
touch cache -t "$now"
echo "new files added" | mail -s "new build" myemail#myserver.com
endif
and this is the error I get
$ ./scr
if: Badly formed number.
$
This page mentions that "Numbers in the C-shell must be integers", so I tried
set now=`date +%Y%m%d%H%M`
but I get the same error still.
I cut down your script to this:
#! /bin/tcsh
if ( -n "`find ./monme -newer ./cache`" ) then
echo hello
endif
This gives the same error. I think the culprit is
-n "`find ./monme -newer ./cache`"
What is -n supposed to do? I think it wants a number, but gets something else...
Update: -n in bash means "length of string is non-zero". In my version of tcsh it is as easy to replace as to use == "" like this:
if (( ! -f "./cache" ) || ("`find ./monme -newer ./cache`" != ""))
then
touch cache -t "$now"
echo "new files added" | mail -s "new build" myemail#myserver.com
endif
Try that and see if it works.