Hey all, I have two related issues. I'm going to post them in two threads because the address different problems.
The problem is writing script code that is universal between bash and sh etc.
I have a vistastop script that is run, by the linux system service manager (systemd). Here is the script:
1 #!/bin/bash
2 #vistastop
3
4 #---------------------------------------------------------------------------
5 # K. Toppenberg, MD
6 # Edited 5/12/21
7 # This script is called from systemd, as configured by
8 # /etc/systemd/system/vista.service
9 # Output of this script will be output to systemd log file, so no
10 # need in here to output to log file directly.
11 #---------------------------------------------------------------------------
12
13 echo "Starting /opt/worldvista/EHR/bin/vistastop.sh"
14
15 #The TMG-specific file below will trigger this system
16 # to shut down via a crontab script.
17 #Since we are shutting down, make sure it is gone,
18 # so on restart, another shutdown will be avoided
19
20 if [ -f /tmp/SHUT_DOWN_REQUEST ] ; then
21 rm /tmp/SHUT_DOWN_REQUEST
22 fi
23
24 source /opt/worldvista/EHR/etc/env
25
26 echo "In vistastart.sh, gtm_dist=$gtm_dist, vista_home=$vista_home"
27
28 $gtm_dist/mumps -run %XCMD "S U=\"^\" D GROUP^ZTMKU(\"SMAN(NODE)\"),GROUP^ZTMKU(\"SSUB
29
30 # Wait for TaskMan to stop
31 echo "Waiting for TaskMan to stop (10 sec)"
32 sleep 10
33
34 processes=$(pgrep mumps)
35 if [ -n "${processes}" ] ; then
36 echo "Stopping any remaining M processes nicely"
37 pgrep mumps | xargs --max-args=1 "mupip" stop
38 sleep 2
39 fi
40
41 processes=$(pgrep mumps)
42 if [ -n "${processes}" ] ; then
43 echo "M process are being shutdown forcefully!"
44 ps -ef | grep mumps
45 pkill -9 mumps
46 fi
47
48 rm -fv /tmp/gtm_*
49
50 #===========
51
I think we got this script from someone else and modified it for our purposes.
It is currently working properly through systemd
This morning, my VistA system was hung (see other thread), so I needed to take VistA down and back up. I could have done this by taking the entire server down, but I thought I could just run the vistastop.sh directly. I probably should have done this by instructing systemd to restart the service, but I couldn't remember the syntax for that.
So I launched the command via this at the linux prompt:
kdt@zz:/opt/worldvista/EHR/bin$ sh ./vistastop.sh
Here is the output:
kdt@zz:/opt/worldvista/EHR/bin$ sh ./vistastop.sh
Starting /opt/worldvista/EHR/bin/vistastop.sh
./vistastop.sh: 24: source: not found
In vistastart.sh, gtm_dist=, vista_home=
./vistastop.sh: 28: /mumps: not found
Waiting for TaskMan to stop (10 sec)
Stopping any remaining M processes nicely
xargs: mupip: No such file or directory
M process are being shutdown forcefully!
kdt 220662 1 0 Jan25 ? 00:03:08 /opt/worldvista/EHR/m/mumps -direct
kdt 238795 1 0 Jan25 ? 00:02:27 /opt/worldvista/EHR/m/mumps -direct
kdt 238882 1 0 Jan25 ? 00:02:27 /opt/worldvista/EHR/m/mumps -direct
kdt 238904 1 0 Jan25 ? 00:02:27 /opt/worldvista/EHR/m/mumps -direct
kdt 238943 238938 0 Jan25 ? 00:02:27 /opt/worldvista/EHR/m/mumps -run GTMLNX^XWBTCPM
kdt 336721 336716 0 05:51 ? 00:00:17 /opt/worldvista/EHR/m/mumps -run GTMLNX^XWBTCPM
kdt 354448 354438 0 07:02 pts/1 00:00:00 grep mumps
Thu 26 Jan 2023 07:02:33 AM EST Server stopped.
Done with /opt/worldvista/EHR/bin/vistastop.sh
In the above, I have highlighted 2 errors. The second one is caused by the first.
Because I wanted the database to be rundown etc, I then manually executed the source command directly from the bash prompt to setup my environment, then launched the script again. Output as below
kdt@zz:/opt/worldvista/EHR/bin$ source /opt/worldvista/EHR/etc/env
kdt@zz:/opt/worldvista/EHR/bin$ sh ./vistastart.sh
Starting /opt/worldivsta/EHR/bin/vistastart.sh
./vistastart.sh: 15: source: not found
In vistastart.sh:
gtm_dist=/opt/worldvista/EHR/m
vista_home=/opt/worldvista/EHR
running as user kdt ()
./vistastart.sh: 23: [: -eq: unexpected operator
Recovering old journals...
%YDB-I-MUJNLSTAT, Initial processing started at Thu Jan 26 07:03:48 2023
%YDB-I-SHMREMOVED, Removed Shared Memory id 5 corresponding to file /opt/worldvista/EHR/g/mumps.dat
%YDB-I-MUJNLSTAT, Backward processing started at Thu Jan 26 07:03:48 2023
%YDB-I-MUJNLSTAT, Before image applying started at Thu Jan 26 07:03:48 2023
%YDB-I-FILERENAME, File /opt/worldvista/EHR/j/mumps.mjl is renamed to /opt/worldvista/EHR/j/mumps.mjl_2023026070348
%YDB-I-MUJNLSTAT, Forward processing started at Thu Jan 26 07:03:48 2023
%YDB-S-JNLSUCCESS, Show successful
%YDB-S-JNLSUCCESS, Verify successful
%YDB-S-JNLSUCCESS, Recover successful
%YDB-I-MUJNLSTAT, End processing at Thu Jan 26 07:03:48 2023
%YDB-I-MUFILRNDWNSUC, File /opt/worldvista/EHR/g/mumps.dat successfully rundown
%YDB-I-FILERENAME, File /opt/worldvista/EHR/j/mumps.mjl is renamed to /opt/worldvista/EHR/j/mumps.mjl_2023026070348_0
%YDB-I-JNLCREATE, Journal file /opt/worldvista/EHR/j/mumps.mjl created for database file /opt/worldvista/EHR/g/mumps.dat with BEFORE_IMAGES
%YDB-I-JNLSTATE, Journaling state for database file /opt/worldvista/EHR/g/mumps.dat is now ON
Starting TaskMan
./vistastart.sh: 50: 1: not found
Thu 26 Jan 2023 07:03:49 AM EST Server started.
Leaving /opt/worldivsta/EHR/bin/vistastart.sh
I highlighted 2 additional errors now encountered. These make no sense to me because the line numbers don't show the code that is reported as erroneous. I can't fine "-eq" anywhere in the script. Here is the environment script "env"
1 #!/bin/bash
2 # 5/6/21 ktoppenberg
3
4 export vista_instance="EHR" # Like EHR, training, dev.
5 export vista_user="kdt"
6 export vista_port="9260" # Listening port for clients like CPRS.
7 export vista_home="/opt/worldvista/EHR"
8 export VH=${vista_home} # a short name for paths, etc - temp
9 export gtm_dist="${VH}/m"
10 export text_user="text9260" # id for text users. Default is text$vista_ins
11 export m2web="/opt/worldvista/EHR/web/m2web"
12 export PATH="${VH}/m:${PATH}"
13
14 export vsb_compliant=1
15 export vsb_version="0.10"
16 export GTMXC_md5="$VH/web/m2web/xc/gtm_md5.xc" # MD5 Library external-call table
17 #export GTMXC_md5="${VH}/w/xc/gtm_md5.xc"
18
19 export gtm_path=$gtm_dist
20 export gtm_sysid="$vista_owner"
21 export gtm_vista="$VH"
22 export gtm_log="$VH/log"
23 export gtmgbldir="$VH/g/mumps.gld"
24 export gtmroutines="${VH}/o*(${VH}/p ${VH}/r) $gtm_dist/libgtmutil.so ${gtm_dist}"
25 export gtm_zinterrupt='I $$JOBEXAM^ZU($ZPOSITION)'
26 export GTM_REPLICATION=off
27 export gtm_prompt="yottadb>"
28
29 alias rundown='$gtm_dist/mupip rundown -r "*"'
30 alias GTM="$gtm_dist/mumps -direct"
31 alias gtm="$gtm_dist/mumps -direct"
32 alias ydb="$gtm_dist/mumps -direct"
33 alias mupip="$gtm_dist/mupip"
34 alias GDE="$gtm_dist/mumps -r ^GDE"
35 alias gde="$gtm_dist/mumps -r ^GDE"
36 alias LKE="$gtm_dist/lke"
37 alias lke="$gtm_dist/lke"
38 alias DSE="$gtm_dist/dse"
39 alias dse="$gtm_dist/dse"
40
41 #Required due to GT.M change as of 6.0-002A
42 export gtm_boolean=1
43 export gtm_side_effects=1
44 export gtm_zquit_anyway=1
45
46 unset VH
47
From past experience, I think the problem is that I evoked the command via "sh", which the man page indicates is short for "dash", with the following description
DESCRIPTION
dash is the standard command interpreter for the system. The current version of
dash is in the process of being changed to conform with the POSIX 1003.2 and
1003.2a specifications for the shell. This version has many features which make
it appear similar in some respects to the Korn shell, but it is not a Korn shell
clone (see ksh(1)). Only features designated by POSIX, plus a few Berkeley exten‐
sions, are being incorporated into this shell. This man page is not intended to
be a tutorial or a complete specification of the shell.
In retrospect, I should have (but didn't) launched the command via:
kdt@zz:/opt/worldvista/EHR/bin$ ./vistastop.sh
which would have used the #!/bin/bash to execute the script. But it is an ingrained habit of mine to use: sh /<scriptname.sh>
Question:
1) Is there a universal way to achieve the source command that will work in both bash and sh?
2) Any ideas about the "-eq" error. And what is the universal way to do this?
Any other thoughts?
Thanks
Kevin T