You are not logged in.
I'm using a simple script to connect to my wireless network. When run, there is no output, and I'm not connected. Here's the script:
#!/bin/bash
exec ip link set wlp3s0 up
exec iw dev wlp3s0 connect "Wireless_Service"
exec dhcpcd wlp3s0The weird thing (to me) is that when I run these commands from the terminal, it works just fine.
Offline
First, the 'exec' commands are supurfluous and can be removed.
Add `set -eu` below the shebang (#!/bin/bash) which will tell bash to abort if any command fails. Lastly, execute the script with `bash -x` to execute it in debug mode (ie, bash -x /path/to/this/script.sh)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Ok, its working now, I'm not sure why now. But now I know how to debug it if it stops. Thanks! Actually, I have another question. This script requires root access, and I'd like to run it when I log in. It's okay to me if the script asks the user for root password (I'm the only user). Is there a way to have a script do this? I've tried doing a 'su' in the script, but I'm not sure how to leave the script not logged in with root priviledges, and I'm guessing doing a 'su' in a script isn't a good idea.
Last edited by insanoflex (2017-05-01 00:02:33)
Offline
#!/bin/sh
if [ $UID != 0 ]; then
sudo $0
exit
fi
# payload action hereBut you can also just sudo the commands inside. You'll be asked for the first one and then the sudo cache covers the other two.
Or: you just execute the script as sudo from your bashrc AND allow it NOPASWD in sudoers.
Be aware that the script should be smarter for auto-invocation, because it will raise conflicts on multiple logins.
Offline
Why not just use systemd-networkd? You get much better fault handling, good logging and you don't have to jump through all these janky hoops...
Offline