You are not logged in.
I'm using wicd for managing my network connections but I'm writing a bash script and want to be able to disable/enable my network connections via command line. I tried
/etc/rc.d/network stop[start]
but it doesn't work, which makes sense because I'm using the wicd daemon, not the network/networkmanager. So I tried:
/etc/rc.d/wicd stop[start]
but that seems to just disable the gui and not the network. Is there some way I can do this while keeping wicd as my network manager?
-SMRT
Offline
ifconfig eth0 down/up? (or other interface instead of eth0)
Offline
ifconfig eth0 down/up? (or other interface instead of eth0)
Yay, I <3 you.
Is there a way to query for which interface is connected and then disable/enable it?
EDIT: I've got another problem, for some reason I'm getting the error "line 16: ifconfig: command not found", no idea why because the command works perfectly fine in a terminal. Here's my script
#!/bin/bash
# trap CTRL-C and restart the network
trap 'ifconfig eth0 up && ifconfig wlan0 up' INT
# reset CTRL-C functionality
trap - INT
# Study loop
COUNTER=0
while [ $COUNTER -lt 10 ]; do
ifconfig eth0 down #&& ifconfig wlan0 down
# sleep 30m
# ifconfig eth0 up && ifconfig wlan0 up
# sleep 10m
done
Last edited by iamsmrt (2009-10-27 21:36:02)
Offline
hmmmmm...Bringing an interface up requires root privileges, so if you're trying to bring it up as non-root, you might get that error..
Offline
That's the error I get when I try (study is the name of the script):
sudo study
If I don't have the sudo, it gives a different error
SIOCSIFFLAGS: Permission denied
which is the error I get when trying "ifconfig eth0 down" without the sudo on the command line.
Offline
chmod +x study
Offline
Yea, it's already an executable and in my path.
Last edited by iamsmrt (2009-10-27 23:33:28)
Offline
ifconfig normally resides in /sbin. Check to see if ifconfig is in your path.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
ifconfig normally resides in /sbin. Check to see if ifconfig is in your path.
Yup, it's in my path.
Offline
I put "sudo ifconfig..." into the script and it worked, why is that? The behavior seems to be that sudo *script* doesn't actually perform all the commands with root priveleges.
Offline
do you have noexec in the sudoers file?
Offline
do you have noexec in the sudoers file?
Nope.
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
# Failure to use 'visudo' may result in syntax or file permission errors
# that prevent sudo from running.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
Defaults env_keep="VISUAL"
# Runas alias specification
# User privilege specification
root ALL=(ALL) ALL
brian ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
Offline
Boy, this is really annoying. It prompts me for my password everytime my script plays with the interface (30 min, 10 min, 30 min, 10 min, etc.), I'd really like a way to get around that but it's difficult with the weird sudo functionality.
Offline
Oh I found out why, I think.
Trap is a weird shell function thing. It's not a bin so sudo doesn't like it.
Either specify what environment values to keep in sudoers or do sudo -E scriptname.
Last edited by gog (2009-10-28 03:11:22)
Offline
Oh I found out why, I think.
Trap is a weird shell function thing. It's not a bin so sudo doesn't like it.
Either specify what environment values to keep in sudoers or do sudo -E scriptname.
I figured it out, instead of "sudo ifconfig" I used the full path "/sbin/ifconfig". This fixes it all .
Offline
Is there a way to query for which interface is connected and then disable/enable it?
#ifconfig -a
The -a flag will show you All interfaces. You can see if they are connected if they have an address.
Offline