5

My goal was to make my Pi create its own WiFi on start so that I can connect to it wirelessly.

I have succeeded by creating a crontab entry (using sudo crontab -e):

@reboot /path/to/create_ap.sh &

where create_ap.sh is a script launching create_ap:

#!/bin/bash
sudo create_ap -n wlan0 MySSID MyPass --daemon

However, I've failed to do this without an additional script: both

@reboot create_ap -n wlan0 MySSID MyPass --daemon

and

@reboot create_ap -n wlan0 MySSID MyPass --daemon &

didn't work as expected (I've also tried to add full path, /usr/bin/create_ap like suggested in comments but that didn't help).

So does crontab allow parameters after the command? (I suspect that only @reboot create_ap bit works in practice, but failed to google that) Or is there some other problem with these lines in crontab and I can adjust them so that an external script is not needed?

YakovL
  • 159
  • 6
  • Does using the full path to create_ap in your crontab work? (I believe the path is /usr/bin/create_ap). Does your crontab change the PATH variable in any other way? – Aurora0001 Jan 01 '18 at 10:56
  • 1
    @Aurora0001 thanks, which create_ap says /usb/bin/create_ap and I've tried full path in crontab but that didn't help – YakovL Jan 01 '18 at 17:51
  • Is this a user crontab, or your system crontab? If it's a user crontab (created with crontab -e) one difference is that the command kicks off as your user, whereas your script includes sudo to execute the command as root. This should go into a system crontab to execute as root on startup. – bobstro Jan 02 '18 at 14:38
  • @bobstro I only used sudo crontab -e so that's root crontab, I guess. Will add this to the question – YakovL Jan 02 '18 at 18:44
  • You've specified a path to the script in your working example, but not a path the the create_ap script in the non-working entries. Try prepending a path to create_ap. Check logs or email for errors. – bobstro Jan 02 '18 at 20:06
  • @bobstro I've already tried that like Aurora0001 has suggested, even edited the question ("I've also tried to add full path, /usr/bin/create_ap like suggested in comments but that didn't help"). Though, I'm not sure what logs to check and how to check email yet. – YakovL Jan 02 '18 at 23:22
  • 1
    As an alternative to crontab, you might be interested in: https://blog.usedbytes.com/2019/11/run-at-startup-without-rc.local/ – ukBaz Sep 07 '20 at 14:14
  • Is this a serious question - or a game you are playing? I ask because: a) the question is nearly 3 years old, and b) starting WiFi AP is something the system will do without a cron job. I'd suggest you delete this question, and start over. – Seamus Sep 07 '20 at 17:37
  • @Seamus it was a serious question back than, why would I delete it after 3 years later? I got 4 upvotes (I suspect you're the one who downvoted) so this is probably an issue others have. starting WiFi AP is something the system will do without a cron job – please elaborate, this didn't happen by itself in my case. – YakovL Sep 08 '20 at 10:15
  • @ukBaz thanks for the suggestion, currently that project of mine is "archived" but I may return to it and will try your suggestion in that case – YakovL Sep 08 '20 at 10:16
  • YakovL: Yes, I downvoted your question. Downvoting means I feel it "shows no research effort", or "is not useful". No - it doesn't happen by itself; it's a computer, not a magic lamp. Did you try an Internet search for an answer to your question? A search on "raspberry pi wifi" returns this item titled "Setting up a wireless LAN via the command line". It's from the "official" documentation - one of thousands of results returned. Try it. If it doesn't work for you, consider editing your question to let us know. – Seamus Sep 08 '20 at 20:12
  • @Seamus oh, now I finally see what bothers you, I've asked about cron on an example that's actually easier solved without cron. That may be true, I can't really say what I've googled back than and why I tried cron and not some other method. However, the question is about cron and not about setting a wireless connection because I wanted to know more about cron. I've searched a bit but haven't found why what I tried didn't work, so I've asked here. No, I don't have another, more pressing issue regarding cron at hand to rewrite this question, sorry. – YakovL Sep 09 '20 at 13:50
  • Yes - it is true... FWIW, I just checked, and in a search using the word cron there are 1,003 Q&A here on RPi SE. You might also look at systemd for starting things. An entire world of help is out there - all for the cost of a search. – Seamus Sep 09 '20 at 20:26

1 Answers1

0

Well, the .sh script calls sudo before create_ap. Either run the crontab entry as root, or prepend the sudo. So try @reboot sudo /usr/bin/create_ap -n wlan0 MySSID MyPass --daemon

steviethecat
  • 261
  • 1
  • 13
  • I used sudo crontab -e which means I used the first option, right? I've read also that the second option is not a proper approach: https://askubuntu.com/a/173930/532531 (but actually I've already tried the line you proposed as well) – YakovL Jan 02 '18 at 18:48
  • Yes, sudo crontab -e works if you want to run the crontab entry as root directly. Considering the second option, you can mitigate that risk from the link by putting pi ALL= NOPASSWD: /usr/bin/create_ap in /etc/sudoers.d/pi. – steviethecat Jan 03 '18 at 07:41
  • Reading https://github.com/oblique/create_ap also gives the alternative to start it from systemd (also check https://github.com/oblique/create_ap/issues/4). – steviethecat Jan 03 '18 at 07:44