Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.