I am hosting a discord bot on a linux server using powershell. But whenever I exit putty it kills the powershell process. How do I keep it running?
Asked
Active
Viewed 570 times
0
-
Welcome to Stack Overflow! This is not really a [programming question](https://stackoverflow.com/help/on-topic). And it has been asked zillion times already. For example https://stackoverflow.com/q/27365021/850848 – Martin Prikryl Dec 02 '21 at 19:00
2 Answers
0
On the linux side, use &
to run the process in the background, and the nohup
command to keep running when your user exits a shell (putty session):
# Run your command
[user@server ~]$ nohup pwsh -Command 'Do-Thing -Foo a -Bar b' &
# Or run a script
[user@server ~]$ nohup pwsh -File /path/to/script.ps1 &
It will show up as a job in jobs
, but only until you disconnect:
[user@server ~]$ jobs
[1]+ Running nohup pwsh -Command 'Sleep -100' &
# bring the job to the foreground and kill it, for example
[user@server ~]$ fg 1
[user@server ~]$ ^C
Once you disconnect, the job will run on its own. Use ps
to find the running process and kill it if needed:
[user@server ~]$ ps -e | grep pwsh
30975 ? 00:00:01 pwsh
[user@server ~]$ kill 30975
If you want something more robust (like auto-restart if crashed), you can set it up to run as a service, but the steps for that can vary between flavors of linux.

Cpt.Whale
- 4,784
- 1
- 10
- 16
-
Consider posting your answer to some of the many duplicate questions instead. – Martin Prikryl Dec 03 '21 at 07:17
-1
In powershell use:
powershell -noExit "cf ssh app_name"
It is possible to set a powershell function to shorten it:
function psne { powershell -NoExit $args[0]}
Then run
psne "cf ssh app_name"

Peter Csala
- 17,736
- 16
- 35
- 75

Marcucus _
- 88
- 10