LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


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

Rep: Reputation: Disabled
Run a command after sleep


hi,
i would like to run the following command

command:" ./serialdump-linux -b115200 /dev/ttyUSB2 |tee test.csv "

Its need to wait 10 second before run the program and then it need to run the program for 100 second

after 100 second, program need to kill

Whats the possible way to run this in linux??

is it possible to run a beep before start the command and before kill the program?/

I am a newbie with linux

any help will be appreciated

Thanks
 
Old 09-29-2018, 09:37 AM   #2
lougavulin
Member
 
Registered: Jul 2018
Distribution: Slackware,x86_64,current
Posts: 279

Rep: Reputation: 100Reputation: 100
Hi,

You can wait for N seconds :
Code:
sleep N
Launch your command in background :
Code:
./serialdump-linux -b115200 /dev/ttyUSB2 |tee test.csv &

# keep its PID
PID=$!
Wait again for M seconds.

And kill the command :
Code:
kill $PID
 
Old 09-29-2018, 09:41 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,327
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
You can also use timeout to limit the duration.

Code:
/usr/bin/timeout 100 ./serialdump-linux -b115200 /dev/ttyUSB2 |tee test.csv &
It's there among the GNU core utilties. See "man timeout".

You might also want to use a full path to the serialdump-linux script.
 
Old 09-29-2018, 09:44 AM   #4
HabibR
LQ Newbie
 
Registered: Sep 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi,
Thanks for your reply
Do i need to make it as script or run in the command prompt?
Thanks



Quote:
Originally Posted by lougavulin View Post
Hi,

You can wait for N seconds :
Code:
sleep N
Launch your command in background :
Code:
./serialdump-linux -b115200 /dev/ttyUSB2 |tee test.csv &

# keep its PID
PID=$!
Wait again for M seconds.

And kill the command :
Code:
kill $PID
 
Old 09-29-2018, 10:19 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
Quote:
Originally Posted by HabibR View Post
Do i need to make it as script or run in the command prompt?
No, you don't need to make script, but if you wish to run it several times better to construct one.
Actually it only depends on you.
 
Old 09-29-2018, 10:49 AM   #6
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 it is a one time run then command line will work, if you plan on reusing it, a script will save you time in having to rewrite it again and again...
 
Old 09-29-2018, 12:45 PM   #7
HabibR
LQ Newbie
 
Registered: Sep 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
thanks

Hi,
Thanks
This one works for me


Quote:
Originally Posted by Turbocapitalist View Post
You can also use timeout to limit the duration.

Code:
/usr/bin/timeout 100 ./serialdump-linux -b115200 /dev/ttyUSB2 |tee test.csv &
It's there among the GNU core utilties. See "man timeout".

You might also want to use a full path to the serialdump-linux script.
 
Old 12-27-2019, 09:42 PM   #8
KenUnix
LQ Newbie
 
Registered: Dec 2019
Location: Pennsylvania
Distribution: linuxubuntu
Posts: 28

Rep: Reputation: 6
The guys are rite on. To do exactly what you ask
create a simple script containing the following
then chmod to 755 scriptname to make it executable.
Way back when I was a newbie I found it helpful to see examples.

#!/bin/bash
sleep 10
timeout 100 <your command>
echo "Terminated"


Then to execute type in ./scriptname

#!/bin/bash means use the bash shell.
sleep xx means wait for a period of seconds.
timeout means let a command execute for a period of time in seconds.
 
  


Reply

Tags
command line interface, python, script



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to Run a Script on wake up from Sleep state bogzab Slackware 5 04-19-2012 04:00 PM
SUSPEND (sleep) command seelk Linux - Software 3 11-17-2009 12:13 PM
Scripts to run after resume from sleep brixtoncalling Slackware 2 09-06-2009 03:27 PM
There is Sleep, Watch Packages but not : run for X minutes, then stop :( frenchn00b Linux - General 9 06-29-2008 05:55 AM
Change job state from SLEEP to RUN sun_sun Programming 1 11-24-2007 11:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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