0

I am a total noob in shell scripting. I am creating a .sh file with multiple commands, but my problem is that the last command is an executable file that after executing stays open and the processes keep running in the terminal until I close the terminal or press Ctrl+C or \. I want to kill these processes or quit the terminal which will also kill the process automatically while running the .sh file. This is the script so far:

#!/usr/bin/env bash
cd ./var/www/testGraduationProject1/public/Hume2Compiler/bin/
export PATH=$PATH:`pwd`
humec -lotsaspace tails.hume;
./tails > hello.txt

I have tried these two commands but they just stop the loading of process in terminal, but without closing the terminal or the process itself.

killall tails
stty -a | grep inter
1
  • 1
    You can send SIGQUIT with kill -3 <pid>. Not sure if that will do what you want though. Commented May 29, 2012 at 19:44

2 Answers 2

1

Your question is vague, but I assume you're asking how to make the tails command run for N seconds then kill it?

If so, use the timeout command (installed by default in 12.04).

Here's your script using timeout (removed some redundant code while I was at it). It runs tails for 10 minutes (600 seconds) before killing it with the TERM signal.

#!/usr/bin/env bash
PATH=$PATH:$PWD/var/www/testGraduationProject1/public/Hume2Compiler/bin
humec -lotsaspace tails.hume
timeout 600 tails > hello.txt

See http://mywiki.wooledge.org/BashFAQ/068 for more information.

1
  • perfect this is better than what i needed. thank you Commented May 30, 2012 at 0:03
0

Try this:

Put this line explicitly in the background:

./tails > hello.txt&

Then add

pkill tails

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.