LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2006, 12:19 AM   #1
mr_scary
Member
 
Registered: Aug 2006
Posts: 39

Rep: Reputation: 15
stopping command issued from shell script


I have a bourne shell script with a menu. One menu entry is for running an executable to produce output on the screen. How can I stop this program and get kicked back to my script (menu)? So far all I can do is Ctrl-C which kicks me back to my command prompt. I am using the bash shell on OpenBSD.
 
Old 11-02-2006, 12:48 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
did you try to use
Code:
executable &
disown $!
here disown is optional
 
Old 11-02-2006, 12:53 PM   #3
mr_scary
Member
 
Registered: Aug 2006
Posts: 39

Original Poster
Rep: Reputation: 15
Well the executable is one that continues to show output (it shows logs of a busy server). So putting it in the background does not help. I already tried this before posting and I get back to my menu but of course the output crashes through. Although I did not try the disown command.
 
Old 11-02-2006, 01:43 PM   #4
//////
Member
 
Registered: Nov 2005
Location: Land of Linux :: Finland
Distribution: Arch Linux && OpenBSD 7.4 && Pop!_OS && Kali && Qubes-Os
Posts: 824

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
You should post that script here, it is kinda hard to give examples how to modify that script without seeing it
 
Old 11-02-2006, 03:54 PM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by //////
You should post that script here, it is kinda hard to give examples how to modify that script without seeing it
Yes I'd agree and perhaps you can also post the necessary outputs if you like. I think I can give a solution to your problem as I made a big bunch of scripts similar to your script but I'd like to see the code first.
 
Old 11-02-2006, 04:08 PM   #6
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
You should use the "trap" command in the shell to ignore Ctrl-c. See "man bash" and "man -a signal".
 
Old 11-16-2006, 02:11 PM   #7
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Well?
What happened?
Did you find something that works?
 
Old 01-11-2007, 11:16 PM   #8
mr_scary
Member
 
Registered: Aug 2006
Posts: 39

Original Poster
Rep: Reputation: 15
This worked for me:

Code:
#!/bin/sh
...
...
...
echo -en "Press ENTER to see output and ENTER again to stop it. "
read CHOICE

echo
command &
read
kill $!
Peter
 
Old 01-12-2007, 08:58 AM   #9
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
from man bash:
Quote:
If the operating system on which bash is running supports job control, bash contains facilities to use it. Typing the suspend character (typically ^Z, Control-Z) while a process is running causes that process to be stopped and returns control to bash. Typing the delayed suspend character (typically ^Y, Control-Y) causes the process to be stopped when it attempts to read input from the terminal, and control to be returned to bash. The user may then manipulate the state of this job, using the bg command to continue it in the background, the fg command to continue it in the foreground, or the kill command to kill it. A ^Z takes effect immediately, and has the additional side effect of causing pending output and typeahead to be discarded.
Would this work better/also?
 
Old 01-12-2007, 12:18 PM   #10
mr_scary
Member
 
Registered: Aug 2006
Posts: 39

Original Poster
Rep: Reputation: 15
Suspending the running process wouldn't help at all. That would effectively bring the user back to the command prompt. You may not have grasped what I'm trying to do here. Reread my first post and report back.
 
Old 01-12-2007, 03:29 PM   #11
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
No need to get sarcastic; I did grasp what you are trying to do, but since you didn't post your entire script, or better yet a working subset of it, I had no way to test my idea on your code.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use cut command in the shell script narendra.pant Linux - Newbie 3 06-01-2006 09:46 PM
Timestamp of previous command issued benjaminrtz Linux - General 1 04-16-2005 01:53 AM
command from shell script notworking Grassie Coetzee Linux - Software 1 03-14-2005 04:39 PM
Command in shell script Grassie Coetzee Linux - Software 1 03-13-2005 11:42 AM
issued when trying to write a firewall script Chypmunk Linux - Security 16 03-29-2002 09:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration