0

I have below shell script, cmdx is testtool command that waits untill the execution and once execution is completed next command echo "End test" is executed.

#!/bin/bash
echo "Starting tests"
cmdx
echo "End test"

I need to set some hardcoded execution time(example: duration 60 mins) for cmdx. post 60 mins cmdx should be stopped and next command echo "End test" should be executed Can you please help on how we can achive this.

2 Answers 2

2

There is a timeout(1) command.

timeout 3600 command arguments...

will kill command after 3600 seconds. You can select the signal with -s option.

Just note that because timeout is an external command, the command must be an external command (can't be shell function). If it isn't, you can have something like

#!/bin/bash
if [ "$1" = "--inner" ]; then
    multiple
    test
    commands
    …
else
    echo "Starting tests"
    timeout 3600 "$0" --inner
    echo "End test"
fi
Sign up to request clarification or add additional context in comments.

Comments

0

Also this is not the question, why not using a cron job crontab -e to execute the script?

 0 * * * * /bin/sh /path/myscript.sh #exec every 60mins

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.