LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-26-2018, 05:32 AM   #1
HabibR
LQ Newbie
 
Registered: Sep 2018
Posts: 5

Rep: Reputation: Disabled
wait run and stop program


Hi,
I am a newbie to Linux.
I want to run an external program in Ubuntu via the command prompt
Is it possible to run the program on the command line with a wait for 10 seconds, then run 300 seconds and kill the process after that with saving the file in CSV and show the output in command line???
Or its need a script to run? if its need a script then what type of script it needed
Additionally, i need to play a beep sound along with that program
Any help will be really appreciated
Thanks
habib

Last edited by HabibR; 09-26-2018 at 05:35 AM.
 
Old 09-26-2018, 06:07 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
What is an external program?

On the command line:
Code:
$ sleep 10; program&
$ PID=$!
$ sleep 300
$ kill $PID
The ampersand (&) runs your program in the background. $! is the process ID of the last process you ran in the background.

This doesn’t solve your CSV problem, but I don’t understand what you want to save in CSV format.

I don’t understand the beep requirement either. Beep at the beginning, the end or during the program? Take an ASCII table, find the beep character and output it as instructed here: https://stackoverflow.com/questions/...ers-using-echo.
 
Old 09-26-2018, 06:40 AM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
if you want to run a script and be more specif about the app/script pid and sleep pid. this is a function I wrote a long time ago. IT could be of use to you.
Code:
#kill the prior pids leaving the new one

function killOldPid(){
appname=$0
appname="${appname#*/}" #removes ./ from cli to get name in process

if [ $(pgrep -u $USER $appname | wc -l) -ge 2 ] && [ $(pgrep -u $USER sleep | wc -l ) -ge 1 ]; then
	echo "$(pgrep -u $USER $appname | wc -l) "pid# --" $(pgrep -u $USER sleep | wc -l)"
	pkill -u $USER -o sleep
	pkill -u $USER -o $appname 
else
     echo "$appname pid $(pgrep -u $USER $appname ) sleep pid $(pgrep -u $USER sleep)"
fi

}
it was written for a loop so that it kills the prior pid(s) when it calls the external program to run again after a set time.

Last edited by BW-userx; 09-26-2018 at 06:42 AM.
 
Old 09-26-2018, 08:14 AM   #4
HabibR
LQ Newbie
 
Registered: Sep 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi,
Thanks for your reply, I was trying to log the data by Serialdump-linux program.
The requirement of beep in this program is to let the user know that program has started and after certain (300 seconds) when the program close it let the user know the program is stopped. It does not require to run the program in loop
Thanks



Quote:
Originally Posted by berndbausch View Post
What is an external program?

On the command line:
Code:
$ sleep 10; program&
$ PID=$!
$ sleep 300
$ kill $PID
The ampersand (&) runs your program in the background. $! is the process ID of the last process you ran in the background.

This doesn’t solve your CSV problem, but I don’t understand what you want to save in CSV format.

I don’t understand the beep requirement either. Beep at the beginning, the end or during the program? Take an ASCII table, find the beep character and output it as instructed here: https://stackoverflow.com/questions/...ers-using-echo.
 
Old 09-26-2018, 08:57 AM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
The beep requirement is easy to fulfill, just echo the beep character before you run program and before (or after) you kill it. You compute has to be configured to actually beep rather than "beep" by flashing the screen.

I can't help with the CSV requirement, because I don't know how the output of serialdump-linux is structured. If its output goes to stdout, use the tee command to send it to a file and the screen.
 
  


Reply



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
segment fault (core dumped)show and program run stop vivek singh chauhan1 Linux - Newbie 2 07-21-2017 02:18 PM
LXer: Wait, STOP: Are you installing Windows 10 or ransomware? LXer Syndicated Linux News 0 08-01-2015 11:00 PM
[SOLVED] Making the program to wait for keyboard input. stf92 Programming 7 04-16-2015 03:30 PM
Wait for one process to stop before starting another? Jykke Linux - Software 3 07-13-2011 09:37 AM
Stop java program(threaded program..should end cleanly) rmanocha Programming 4 11-09-2004 09:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:09 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