How to perform this with a dos command:
while (true)
myDOSCommand
sleep 5s
:forever
myDOSCommand
sleep 5
goto forever
Related
I am looking for some support on creating some way of running a swift command in terminal to run a program and then stop it after 1 hour then restart.
Example of manual process:
Open Termain.
cd my app
swift run my program --with-parameters
ctrl+c (after 1 hours)
Restart with step 3
I am sure there must be some way using a bash script maybe to start the program by command, kill it after 60min and restart it with a continuous loop like that.
Thanks :-)
You can set up a cron job to do this. Basically, you'll have a bash script, say it's located at /Users/ben/scripts/run_my_program.sh that will, at every hour:
Terminate the current running process (kill pid)
Execute the swift run my program --with-parameters and spit out the process ID
you can get the PID of the swift process you launch with echo $!, and then use sleep 1h to sleep for 1 hour and then kill the process with kill -9 and the PID you got in the first step.
Hey so I was wondering how can I make it so that in my sh script two commands execute at the same time without waiting for one another to finish. As an example I'd like zmap to run and a listener.pl
How could I do this? I know doing this will run zmap then after zmap is over it will run the 2nd command
but I need both to be executed at the same time.
#/bin/sh
zmap
perl listener.pl
Run the jobs in the background by appending & to each command.
#/bin/sh
zmap &
perl listener.pl &
wait
I have a c# program, integrated with a command line program. I want to run the command line program twice(start, finish, start again, finish again). Now I use a timer to set a special time period for every run, for example, give first run 10 seconds, no matter it is finished or not, after 10 seconds, the program starts the second run.
I want the second run can run automatically after the fist run finshed, How to do it? How to detect the first run is finished, and then take a trigger to start the second run?
Assume you run the command line as a process, see this answer to check if the process has finished:
Find out if a process finished running
if (process.WaitForExit(timeout))
{
// user exited
} else {
// timeout (perhaps process.Kill();)
}
In a command line you can launch this command:
start "" /w will execute the command and wait until it is finished before proceeding.
for %a in (1 2) do start "" /w "programA.exe"
Is there any way to put delay between commands e.g we have 5 command i want that run first command and wait for 3 second to run new command, Then run next command and wait for 2 second, Then run 3rd command and wait for 5 second etc etc.
I found WScript.sleep or WScript.sleep()
vbscript:
WScript.sleep(3000) '3000 milliseconds are 3 seconds
powershell:
start-sleep -seconds 3
May you convert this tiny code to Bash code :
user/bin/perl
sleep(300);
system("killall -9 perl &");
sleep(5)
#!/bin/bash
sleep 300
killall -9 perl &
sleep 5
sleep 300
killall -9 perl &
sleep 5
The perl program will kill not only all other perl processes, but also itself, so the functional equivalent translation would be something like
#!/bin/bash
sleep 300
killall -9 perl &
kill -9 $$ &
sleep 5
The final sleep 5 is probably never executed in the original script or in this one, although it is possible that the sleep command at least starts to execute.
If the reason behind translating into bash is exactly that, i.e. the program is supposed not to commit suicide, the other answers are better.
As Dennis Williamson said, in either case, your script should probably not use kill -9 and generally not globally kill, but it depends on your environment if it may have bad side effects.