Can a 4D database function be started from a unix shell script (Mac)? - database

We have large data sets in a 4D database. Recently we needed to automate certain tasks to export, import, or process data, which requires some connection between 4D and the unix shell (bash and zsh).
We did fine whenever a 4D function had to call a shell command or shell script, using the LAUNCH EXTERNAL PROCESS instruction. But I am having trouble doing the opposite, starting a 4D function from a shell script. The on-line documentation did not give me any suggestion on how to do this.
How would I run a 4D function at a specific date+time? 4D itself does not seem to provide a way to schedule an action. OS X provides a perfectly good way to start a command at any future time (weekly or monthly). I just do not know 4D well enough to figure out how to call a 4D function from a shell script. If it was MySQL or PostgreSQL then I had no problem, because I could call the mysql or pgsql client, which can work without a GUI. Can I do something similar with 4D?

There are a couple of ways you could accomplish this in 4D. The way I would typically do this, would be to use the web server in 4D. Then I would trigger that service with a GET or POST using whatever scheduler (cron, windows scheduler, etc) that I like. This does require some web server licensing from 4D.
This gives you flexibility to trigger the event at given times or from an external process. Say your data has been cleaned and is now ready to be imported, you don't have to wait until the next import time, it could just be triggered.
Alternatively you could create a 4D method that runs in its own process. You launch the process at database started and then it would loop indefinitely, checking to see if it needed to trigger whatever action you want.
Take a look at the New process, DELAY PROCESS, and While...End While commands. You could launch the new process to run on the server or a client depending your needs.
Basically your On Startup method calls New Process to run your 'scheduler' method. In that method you have a While (some true condition) loop that checks to see if it should run. Then it sleeps (delay process) for a bit so it doesn't hog resources, wakes up again and runs the loop.
If this is something you want to be able to stop programmatically you can use SET PROCESS VARIABLE to set the value of a variable in the scheduler process from outside. Then have the loop check that value to see if it should exit.

To answer your question, if you want call 4D on Mac from shell you should use a plugin from Pluggers (cfr https://www.pluggers.nl/product/scripting-tools/ ) and osascript.

Related

ansible playbook handling long running process

is it possible to handle processes that are long running and may not keep an application running in the cli. for example zfs scrub /tank completes in a few seconds yet the process of the scrub continues in the background. there is a utility called zed that can run a script or other actions when the scrub completes to get the details of the scrub. is there a way that ansible can handle situations like this to receive results and act on them or is this something that a tool like jenkins would be needed
Use the wait_for module to make Ansible wait for the process to complete.
For example, you could configure the zed utility to create a file when the scrub process completes.
- name: Wait until the file /tmp/scrub-results is present before continuing
wait_for:
path: /tmp/scrub-results
The wait_for module can test many other conditions such as the presence of an open port or specific content to appear in a file. It can also watch a specific process ID until it terminates.
It is best to read the documentation to determine which is most suitable for your use case.

Windows Service with running some Process

I have a problem with windows service. I'd like to his level run the program in a given situation. Every minute check a certain value and if the value is to adopt "truth" is to me the program starts. Only at the moment this does not work ...
The problem is that when debugging the code executes correctly, it displays my window, but the service is run normally nothing happens ...
Link to movies about this all:
https://youtu.be/GPv5dn92BGg
You need to jump through several hoops to launch interactive applications from a service. First, the service needs to be explicitly allowed to interact with the desktop. Then the service needs to specify the correct WindowStation for it to show on.
It may be simpler to just set your child application up as a scheduled task, as these can interact with the desktop for you

how to automate jcl to run a cobol program on mainframe

We have a COBOL batch program that we are able to execute manually from JCL. We want to automate this process so that it can execute every 15 minutes.
Is there a way to automate the execution of a batch program on the mainframe?
I'm a PC guy and I know in windows I can create a .BAT file and set it up in Task Scheduler to run every 15 minutes. I'm essentially trying to do the same thing on the mainframe.
Is there a way to automate the execution of a batch program on the
mainframe?
Yes.
Many mainframe shops have job schedulers. Control-M from BMC is one, ASG has Zeke, there are others.
Having said that, it sounds like the application in question is written to periodically poll for some event. Mainframes typically have better ways of accomplishing tasks people normally solve via polling. Event monitoring, for example.
Mainframe Scheduling software like Control-M from BMC is one, ASG has Zeke, CA7 from CA and IBM TWS for ZOS formerly OPCA can be used to schedule a job every 15 minutes.
You could add a job for every 15 minute period or have the first step of the job be to add the 1 that will run in the next 15 minutes.
Pros
Operators will be notified of the job failing
Cons
Will end up allot of the same jobs in the schedule
TWS for ZOS (what I am know) you would need to add nearly 96 jobs and set the corresponding times for it
The option I would recommend is using an automation product such System Automation from IBM, Control-O from BMC or OPS from CA.
With any of the above automation products you could setup a started task and get them to start it every 15 minutes. It is much easier say for example using 1 panel in System Automation to set it up to run a start task every 15 minutes
If you wanted to know if it fails you could use the automation products to schedule it in any of the above schedulers.
There are so many solutions to this, it really depends on what you are monitoring. Besides the standard "use a job scheduler like CA7" (with the disadvantage of having so many jobs that run during the day, just kind-of messy).
You could either define an address space (started task) that invokes your COBOL code, and within your COBOL code have it sleep (i.e. wait on a timer) for 15 minutes, wake-up check whatever and go back to sleep. Alternatively, run the job on JES2 but you might have to a little extra so that JES keeps the job active all day!
If this code finds a problem then it can also issue a console message (maybe, you might have to write a little bit of assembler code to do issue a WTO or WTOR), so the the operator either knows (WTO) or knows and has to reply (WTOR) (write to operator with reply).

Building an "odometer" for time spent on a server

I want to build an odometer to keep track of how long I've been on a server since I last reset the counter.
Recently I've been logging quite a bit of time working on one of my school's unix servers and began wondering just how much time I had racked up in the last couple days. I started trying to think of how I could go about writing either a Bash script or C program to run when my .bash_profile was loaded (ie. when I ssh into the server), background itself, and save the time to a file when I closed the session.
I know how to make a program run when I login (through the .bash_profile) and how to background a C program (by way of forking?), but am unsure how to detect that the ssh session has been terminated (perhaps by watching the sshd process?)
I hope this is the right stack exchange to ask how you would go about something like this and appreciate any input.
Depending on your shell, you may be able to just spawn a process in the background when you log in, and then handle the kill signal when the parent process (the shell) exits. It wouldn't consume resources, you wouldn't need root privileges, and it should give a fairly accurate report of your logged in time.
You may need to use POSIX semaphores to handle the case of multiple shells logged in simultaneously.
Have you considered writing a script that can be run by cron every minute, running "who", looking at its output for lines with your uid in them, and bumping a counter if it finds any? (Use "crontab -e" to edit your crontab.)
Even just a line in crontab like this:
* * * * * (date; who | grep $LOGNAME)>>$HOME/.whodata
...would create a log you could process later at your leisure.

Checkpointing and restarting X11 applications

I want to checkpoint and restart X11 applications. I am using the BLCR (Berkeley Lab Checkpoint/Restart (BLCR)) tool.
BLCR is not able (without modifications) to reinitiate the connection to the X-Server. I used an interposition library to log all Xlib function calls with their parameters to a text file.
Now I want to be able to re-use this logged function call.
Is there a better way than to save them to a text file and parsing/interpreting them during the restart procedure?
The application which is checkpointed should redo the calls which were logged, but this seems to be not as easy as it has sounded first.
I've not tested this, but I think you might be able to solve this one by spawning an xmove child process and making sure this gets stored in the checkpoints. Your application would talk to xmove instead of the XServer directly and every time you restore from checkpoint you would "move" to the current xserver again.

Resources