I'm using Ubuntu. I have two bash script files. Both will run in parallel. Now I want to continuously monitor on another file that it is running or not.
So any way to find that the file is currently executing or not ?
Numerous possibilities, it is a question of creativity...
Some suggestions:
periodically poll the process list and filter it by name or process id
start the script with control sockets, as long as the sockets are open the script runs
use the usual locking strategy in file system.
have the script do a lifebeat on a regular base, then watch that lifebeat.
start the script in a series of commands, the moment the script exists the next command will be executed by the calling shell. That one could be a notification script or something.
have the script do some wiggling on your desktop and watch it yourself.
start it using nohup and watch the log file.
implement a deamon inside the script and connect periodically.
open a file from within the script and watch the file system using the fuser system call.
periodically write a token into a file by the monitoring script and have the monitored script remove that token, like a baton.
call the script using a blocking call. The script executes as long as that blocking call does not return.
create a singleton strategy on process level and simply try starting it periodically.
make the monitoring script act as a monitor deamon the executing script connects to. If the connection is terminated the scipt obviously has stopped executing.
...
Sorry, this starts getting boring...
Related
Im writing a tool and one of its commands allows you to start a new session
How can I make a golang program restart itself? If your solution is OS-Strict im on Linux.
I tried
// exec from os/exec
exec.Command(os.Args[0]).Run()
but it doesnt work. I get a blank input session which is hard to explain
My Program Input: session new
:(
:(
each of the :( represent a blank line where im able to type stuff and hit enter, there are 2 which means i hit enter twice
Im expecting
My Program Input: session new
My Program Input:
Edit: more accurately, i want to make a subprocess of the same program
You could use a separate process, like radovskyb/gobeat.
Example:
sudo gobeat -pid=1234 -cmd="go run sendemail.go"
Run with sudo so gobeat will restart the server in the same terminal tty that it originated in. (sudo)
Point gobeat to the process of the running server that you want gobeat to monitor. (gobeat -pid=1234)
Set the cmd flag to run a Go file that will send an email notifying you that the server was restarted. (-cmd="go run sendemail.go")
If you do not want a separate process, then consider implementing a graceful upgrade
You can use the library cloudflare/tableflip for instance.
I'm trying to create 10 instances on GCP console through a shell script. The allocation of resources to these instances is done parallelly(All starts getting created at once) or sequentially (Creation of Instance#2 starts when resources have been allocated to Instance#1)?
The Google Cloud Console does not support shell scripts.
If you mean that you are using the SDK CLI gcloud, you have the option --async to not wait for the API command to complete. Otherwise, the commands run one at a time.
The shell itself waits for the program to complete, which does not mean that the instance has been created. There is some overhead in launching gcloud. I do not recommend using the & to launch multiple gcloud commands at the same time.
One last item, check your quota to make sure that you can launch 10 instances in the zone(s) that you desire.
Compute Engine Quotas
Until we can implement our new HEAT SM system i am needing to create some workflows to ease our currently manual user administration processes.
I intend to use Powershell to execute the actual tasks but need to use VBS to send an argument to PS from an app.
My main question on this project is, Can an argument be sent to an already running Powershell process?
Example:
We have a PS menu app that we will launch in the AM and leave running all day.
I would love for there to be a way to allow PS to listen for commands/args and take action on them as they come in.
The reason I am wanting to do it this way is because one of the tasks needs to disable exchange features and the script will need to establish a connection a remote PSsession which, in our environment, can take between 10-45 seconds. If i were to invoke the command directly from HEAT (call-logging software) it would lock up while also preventing the tech from moving on to another case until the script terminates.
I have searched all over for similar functionality but i fear that this is not possible with PS.
Any suggestions?
I had already setup a script to follow this recommendation but i was curious to see if there was a more seamless approach
As suggested by one of the comments by #Tony Hinkle
I would have the PS script watch for a file, and then have the VBScript script create a file with the arguments. You would either need to start it on another thread (since the menu is waiting for user input), or just use a separate script that in turn starts another instance of the existing PS script with a param used to specify the needed action
I'm trying to start a service via a script that I run through cron. Basically it just does this
/local/services/servicename status
/local/services/servicename stop
/local/services/servicename start
The service starts fine if I run the commands myself, but whenever I run it via the script, and I check for the service status manually, its response is always
Servicename Service is not running.
I am truly confuse right now. Any particular reason why a bash script wouldn't be able to start the services?
Not really an answer to your specific question, but definitely a useful tip for debugging cron behavior in general. Cron sends email messages to the user it runs as. If you run that in the root crontab, run the mail command in a terminal as root and you'll see the cron messages in your inbox. Check them by typing the message number (or man mail to learn how to use it).
I have created a Windows Task that runs on Admin account with highest privileges that runs a batch file every minute.
This batch file will execute a PHP script to retrieve a webpage , after which it checks if no page or wrong content is returned.
If the result is negative then the batch routine kills the httpd process and its children using taskkill (I am currently dealing with a PHP hang causing the Apache Http process to hang as well).
This entire process works perfectly when executed while logged onto the machine as admin. However when executing as a task (and despite admin privileges) the process does NOT get killed. There is no event or debug entry.
So my question is why is task kill unable to kill the process, how can I get more info and what alternatives exist?