Sunday, May 5, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1381  / 2 Years ago, thu, november 3, 2022, 12:33:27

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

More From » command-line

 Answers
5

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.


[#38022] Friday, November 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
uccase

Total Points: 473
Total Questions: 100
Total Answers: 110

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
uccase questions
;