简体   繁体   中英

Linux stop a command while its loading in PUTTY/SSH

Let me start of by saying i just started learning linux.

I have a command that keeps processing/loading until i press CTRL+C to cancel/stop the command and remain in session.

What i want is to send that command, wait x amount of seconds and then close it programmatically in a single command (cause i can't enter new commands when its loading). Sorry if it sounds stupid, but that would solve my problem.

Would really appreciate if someone could've helped me out here, couldn't find anything on google that was working (mostly exiting the session while the command remains loading).

Use sleep command for terminate the process. example: echo helloword & sleep 1 --> time indicates in seconds.After executing the echo command it will wait for one second and then it terminate the echo process

use nohup. example:

nohup ./foobar.sh & < /dev/null > ./log 2>&1 
exit

In foobar.sh you can have the following content

command you wish to execute

sleep <no of seconds>

or you can use "screen", you need to install "screen" in you host, then

> screen {your-cmd}

and press ctrl+A followed ctrl+D detach current (but your cmd still running) session .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM