Need help with Bash Script
Hello guys im trying to make a bash script that will run a program and sleep for 15 seconds running the program and it will stop the program and sleep 300 seconds and than start the program again, here the code i have but its not working:
Quote:
I hope someone can help me with this issue. Thanks a lot for all the attention. |
You could use $!:
#!/bin/bash Code:
echo "Starting Ata Pep.." |
You have the function named "start" but then you call "start" from within the function definition. It would need to be called AFTER the function definition. That is to say functions don't get executed when defined but rather when called later in the script. (e.g. calling get_pid in your start function is valid because you previously defined get_pid.)
|
Thanks a lot guys i found out the problem and now its working perfect.
This topic can be post as solved. |
Well as written, the script sets variable PID to null, defines a function "get_pid", defines a function "start", and then exits without ever calling either function. The parameter that you passed when invoking the script is never used.
Once you correct that by inserting a call to "start" (perhaps with a test of the supplied parameter, "$1") following the function definitions, you will find that the script will run for quite a while but will eventually run out of memory due to the infinite recursion of the "start" function calling itself. Rather than doing that, you should just write the body of the "start" function as an infinite loop Code:
while :; do Code:
PID=`pgrep -x ata_pep` |
All times are GMT -5. The time now is 03:46 PM. |