I have a script that displays a menu for my applications with details about them such as PID, runtime, and other static data.
In this script I wait for a user input to preform some actions on the application such as kill \ start \ update.
I want to add to the data I'm displaying, a dynamically changing stat about its CPU usage, and say update it every second.
The problem is that with printf "%s\r" "$(appCPUusage)" is that it requires this print to be the last thing that appears on the screen but I need it to be somewhere in the center of the script, and put the refreshing of $appCPUusage on the background and still allow users to input their action and use the script.
Is that doable on bash?
On the CPUsage column is where I want the dynamically changing var to be.
Thanks.
Related
I am working on a project where I have to send arguments by a command line to a python file (using system exec) and then visualize the results saved in a folder after the python file finishes executing. I need to have this by only clicking on one button, so my question is, if there is any way to realize this scenario or maybe if I can order the events.
Now I have included the flat sequence structure to the block Diagram so I can order the events, but I had an issue with making the program (the python file) running every time I press the Test button (it only runs in the first time I click on the Test button), I tried to use the while loop but I couldn't execute it again unless I restart the program.
The way you phrased your question makes me think that you want to wait until the command you call via system exec finished and then run some code. You could simply use a sequence structure for this.
However, if you need to do this asynchronously, i.e. launch the command and get an event when the command finished so you can draw the results, you will need to resort to asynchronous techniques like "Start Asynchronous Call" and "Wait On Asynchronous Call", or for example queues and a separate code area for the background-work.
Use "wait until completion?" input of System Exec function to make sure the script finished execution, then proceed with the results visualization part.
Background:
Sometime I have the need to monitor the change of a value in a certain program.
My solution is to use a batch file to capture the part of the screen with where the value is shown with Minicap and then use Tesseract to convert the value to plain text. However this script would not work so good if I would need to monitor value change every second for several hours.
Current solution (simplified example):
minicap.exe -captureregion 800 600 850 620 -save C:\file.png -exit -escapequit
tesseract.exe C:\file.png out.txt
Question:
What I would like is some simple way to OCR a value directly from the screen to use in the batch file, perhaps buffer several values before appending them to a csv file. I would prefer to do this without the need to install python or write compiled software
(Posted on behalf of the question author, to move the solution to the answer space).
I found that I could use Capture2Text. The following command takes the on screen text and prints it to stdout:
Capture2Text_CLI.exe --screen-rect "800 600 850 620"
This way it's possible to run the command, check if the value is changed, and if so, append it to a log file together with a timestamp.
I'm working on a bash script that lets the user configure a number of settings (like for example the current driver or list of drivers, the current release, the current test suite, the current compiler or list of compilers, etc) and which works with a number of tools (compilers, misra analyzer, test report creator, etc). The script defines some aliases like for example: compile, test, misra, report, etc. When such an alias is run by the user, the script prepares about 1-3 sample commands that can be run with that tool and echoes the sample commands on the screen like for example:
s1 = misra current_driver current_compiler
s2 = misra current_drivers_list current_compiler
s3 = misra current_drivers_list current_compilers_list
The user looks at the samples, chooses the most appropriate, types s1, s2 or s3
and hits Enter. The script adds the selected command in the history, as top command. The user presses 'up arrow' and has the command ready to be edited if needed and executed when everything is ok, at a hit of Enter key.
Now, I want to speed up the process of selecting the command, by getting rid of that 'up arrow key' press. What I would like to accomplish is: when user types s1, s2 or s3 and hits Enter, the corresponding command is added in the command line, without being executed. The thing is that I want to obtain the same behavior like the command would have been typed by the user, meaning the user should still be able to edit it, before launching it by pressing Enter.
Is there any method I can use to implement this behavior ?
Thank you
Hi I am trying to use screen as part of a cronjob.
Currently I have the following command:
screen -fa -d -m -S mapper /home/user/cron
Is there anyway I can make this command do nothing if the screen mapper already exists? The mapper is set on a half an hour cronjob, but sometimes the mapping takes more than half an hour to complete and so they and up overlapping, slowing each other down and sometimes even causing the next one to be slow and so I end up with lots of mapper screens running.
Thanks for your time,
ls /var/run/screen/S-"$USER"/*.mapper >/dev/null 2>&1 || screen -S mapper ...
This will check if any screen sessions named mapper exist for the current user, and only if none do, will launch the new one.
Why would you want a job run by cron, which (by definition) does not have a terminal attached to it, to do anything with the screen? According to Wikipedia, 'GNU Screen is a software application which can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions'.
However, assuming there is some reason for doing it, then you probably need to create a lock file which the process checks before proceeding. At this point, you need to run a shell script from the cron entry (which is usually a good technique anyway), and the shell script can check whether the previous run of the task has completed, exiting if not. If the previous incarnation is complete, then the current incarnation creates a lock file containing its PID and runs the job. When it completes, it removes the lock file. You should review the shell trap command, and make sure that the lock file is removed if the shell script exits as a result of a trappable signal (you can't trap KILL and some process-control signals).
Judging from another answer, the screen program already creates lock files; you may not have to do anything special to create them - but will need to detect whether they exist. Also check the GNU manual for screen.
Within the GUI of VSS it is possible to view the history of an item 'including' or 'excluding' the labels.
I'm trying to do the same thing but from the command line but I just can't see which switch I need to use in order to 'exclude' labels (by default they are included).
e.g. I'm running:- ss.exe HISTORY -I- $/Source/Path/FileName.txt
Why? We have Cruise Control setup to automatically create a label on each successful build...so there are alot of labels. When I run that 'get history' command above it takes 20-30 secs per file and I want to run a process that will hit every file...
If anyone can tell me which switch I need to use (it must be there if the GUI allows you to choose??) that would help very much :-)
Thanks!
You can use the -L parameter as follows:
ss.exe history -L : shows history labels only
ss.exe history -L- : shows history without labels