0

The question is about running a bash script in background with the ability to logout and the process to continue. The issue is that websocat and wscat don't like when I close the terminal or logout.......

**** NOTE : the script.sh does work when just do script.sh it have the execute permission and there is no error in the script

But when I'm trying nohup, disown, bg, &, &! ===>>>> all of those don't work :(

the content of script.sh

wscat -c "wss://somewebsocketstream" > file

when I run nohup appending output to nohup.out and when I hit enter, the script.sh stops

nohup /script.sh

when I add & I get [1] + suspended (tty input) nohup and .sh stops

when I add &!

whitout nohup and only script.sh & I get [1] + suspended (tty input) when I type any key on the keyboard

only script.sh &! nothing happens, I see it in top but no activity :(

when I try bg script.sh I get bg: job not found

when I try script.sh 2>&1 & or script.sh &> /dev/null & I get [1] + suspended (tty input) 2>&1

7
  • WHat happen when you try nohup command &? May 18, 2022 at 14:04
  • @RomeoNinov when I do nohup ....sh & I get appending output to nohup.out and when I type enter to do something else I get [1] + suspended (tty input) nohup
    – John R
    May 18, 2022 at 14:10
  • Have you check after above command if the program work? May 18, 2022 at 14:11
  • @RomeoNinov when I see suspended (tty input) in the terminal, the process remains inactive and don't work. I have to do jobs to get the pid and kill it manually
    – John R
    May 18, 2022 at 16:27
  • Please edit your question to not have the question in the title but the body, and proofread for grammar and punctuation. The question also has some unnecessary "formatting" making it difficult to read (ex. ===>>>>). The initial paragraph could be better phrased to contain the question. May 23, 2022 at 19:46

1 Answer 1

0

Hi found a python way to do it (so nohup, &, etc works)

https://pypi.org/project/websocket-client/

pip3 install websocket-client

in the .py

from websocket import create_connection
ws = create_connection('wss:.....')
print(ws.recv())
stubfile = open('/pathto.file', 'w+')
stubfile.write(ws.recv())
ws.close()

this py gets 1 message from the wss:// and saves it in a file

I can also add this .py in my crontab -e ....

2
  • 2
    There is no explicit question in the question, but judging by the title I say the question is "why don't these work?". The answer answers "how to get the result I want?". These are different questions. The answer does not answer "why?" at all. You answered your own question. Please consider editing the question or/and the answer, so they match. The easiest way may be to drop "why?" and explicitly ask the question you were willing to answer. If you want to keep "why?" in the hope someone will answer it eventually, then your answer is a partial answer at most. May 22, 2022 at 9:06
  • @KamilMaciorowski I was unable to find the answer of the why... so I found an other solution that works
    – John R
    May 22, 2022 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .