Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wscat returns nothing when launced from a cron @reboot #141

Open
JulienDevillers opened this issue Jul 20, 2022 · 3 comments
Open

wscat returns nothing when launced from a cron @reboot #141

JulienDevillers opened this issue Jul 20, 2022 · 3 comments

Comments

@JulienDevillers
Copy link

Hello,

I want to notify the reboot of a raspberry pi to another server using wscat.
I wrote this script:

#!/bin/sh

date >> reboot.log
cmd="wscat -n -x reboot -c  wss://xxxxxxxxxxxxxxxx.com:18800/sub"

OUTPUT=$($cmd)

echo $OUTPUT
while [ $OUTPUT != "ok" ]; do
  	sleep 30
	OUTPUT=$($cmd)
done

--> it works well from command line with and without sudo. The server returns "ok" and the script stops before entering the loop.

-->When launched from this cronjob :
@reboot /home/pi/xxxxxxxx/rebootNotify.sh
Nothing is returned from the wscat command, the script enters infinitly the loop (The loop exists in case
unavailable network at reboot time. BTW, adding a sleep in the cron before calling the scripts leads to the same
result).
Where is the bug?

note : wscat has been installed using sudo npm install -g wscat.

Thanks
Julien

@lpinca
Copy link
Member

lpinca commented Jul 21, 2022

I don't know, if the script works when run manually it should also work when run as a cron job. Check if the server receives the message. If you don't control it use another one.

Also check the crontab PATH. It is possible that wscat is not found.

@JulienDevillers
Copy link
Author

Thanks for your answer.
I'm sure that server receives nothing and even not a connection attempt.

I echoed the path variable in the script.
Called from my own session, path is
/usr/local/sbin:/usr/local/bin/:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/snap/bin
Called from crontab:
/usr/local/sbin:/usr/local/bin/:/usr/sbin:/usr/bin:/sbin:/bin
I don't see any significative difference.

I also added "which wscat" command that returns in both case the correct path...

@s-wust
Copy link

s-wust commented Jan 16, 2023

I can confirm this behaviour.
Run from bash
/usr/local/bin/wscat -x . -c wss://example.com > /tmp/output.txt
writes the output to output.txt as expected while run from cron
*/1 * * * * /usr/local/bin/wscat -x . -c wss://example.com > /tmp/output.txt
only creates an empty file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants