Skip to main content
Tweeted twitter.com/StackCodeReview/status/938592450729345024
edited tags
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
grammar: disambiguation
Source Link

I use Ubuntu (Trusty and Xenial) and usually put my computer in sleep mode rather than power it down. A common problem is that onupon wake the network manager is down so one has to restart the network-manager service. E.g.

sudo service network-manager restart

I am tired of doing this so I have hacked thisthe following together:

#!/bin/sh

# should live in /lib/systemd/system-sleep/...
# sudo mv restart-network-on-wake.sh /lib/systemd/system-sleep/
# sudo chmod a+x /lib/systemd/system-sleep/restart-network-on-wake.sh

case $1/$2 in
    pre/*)
        echo "Going to $2..."
        exit 0
        ;;
    post/*)
        echo "Waking up from $2..."
        if ! ping -q -c 1 -W 1 8.8.8.8 > /dev/null; then
            echo "IPv4 is down, restarting network-manager"
            service network-manager restart
        fi
        ;;
esac

I am a novice at shell scripting I guess and don't have a strong understanding of Linux internals. Do you have any thoughts?

I use Ubuntu (Trusty and Xenial) and usually put my computer in sleep mode rather than power it down. A common problem is that on wake the network manager is down so one has to restart the service. E.g.

sudo service network-manager restart

I am tired of doing this so I have hacked this together:

#!/bin/sh

# should live in /lib/systemd/system-sleep/...
# sudo mv restart-network-on-wake.sh /lib/systemd/system-sleep/
# sudo chmod a+x /lib/systemd/system-sleep/restart-network-on-wake.sh

case $1/$2 in
    pre/*)
        echo "Going to $2..."
        exit 0
        ;;
    post/*)
        echo "Waking up from $2..."
        if ! ping -q -c 1 -W 1 8.8.8.8 > /dev/null; then
            echo "IPv4 is down, restarting network-manager"
            service network-manager restart
        fi
        ;;
esac

I am a novice at shell scripting I guess and don't have a strong understanding of Linux internals. Do you have any thoughts?

I use Ubuntu (Trusty and Xenial) and usually put my computer in sleep mode rather than power it down. A common problem is that upon wake the network is down so one has to restart the network-manager service. E.g.

sudo service network-manager restart

I am tired of doing this so I have hacked the following together:

#!/bin/sh

# should live in /lib/systemd/system-sleep/...
# sudo mv restart-network-on-wake.sh /lib/systemd/system-sleep/
# sudo chmod a+x /lib/systemd/system-sleep/restart-network-on-wake.sh

case $1/$2 in
    pre/*)
        echo "Going to $2..."
        exit 0
        ;;
    post/*)
        echo "Waking up from $2..."
        if ! ping -q -c 1 -W 1 8.8.8.8 > /dev/null; then
            echo "IPv4 is down, restarting network-manager"
            service network-manager restart
        fi
        ;;
esac

I am a novice at shell scripting I guess and don't have a strong understanding of Linux internals. Do you have any thoughts?

update grammar; separate independent clauses into separate sentences
Source Link

I use Ubuntu (Trusty and Xenial) and usually put my computer in sleep mode rather than power it down my computer. A common problem is that on wake the network manager is down so one has to restart the service. E.g.

sudo service network-manager restart

I am tired of doing this so I have hacked this together:

#!/bin/sh

# should live in /lib/systemd/system-sleep/...
# sudo mv restart-network-on-wake.sh /lib/systemd/system-sleep/
# sudo chmod a+x /lib/systemd/system-sleep/restart-network-on-wake.sh

case $1/$2 in
    pre/*)
        echo "Going to $2..."
        exit 0
        ;;
    post/*)
        echo "Waking up from $2..."
        if ! ping -q -c 1 -W 1 8.8.8.8 > /dev/null; then
            echo "IPv4 is down, restarting network-manager"
            service network-manager restart
        fi
        ;;
esac

I am a novice at shell scripting I guess and don't have a strong understanding of Linux internals,. Do you have any thoughts?

I use Ubuntu (Trusty and Xenial) and usually sleep rather than power down my computer. A common problem is that on wake the network manager is down so one has to restart the service. E.g.

sudo service network-manager restart

I am tired of doing this so I have hacked this together:

#!/bin/sh

# should live in /lib/systemd/system-sleep/...
# sudo mv restart-network-on-wake.sh /lib/systemd/system-sleep/
# sudo chmod a+x /lib/systemd/system-sleep/restart-network-on-wake.sh

case $1/$2 in
    pre/*)
        echo "Going to $2..."
        exit 0
        ;;
    post/*)
        echo "Waking up from $2..."
        if ! ping -q -c 1 -W 1 8.8.8.8 > /dev/null; then
            echo "IPv4 is down, restarting network-manager"
            service network-manager restart
        fi
        ;;
esac

I am a novice at shell scripting I guess and don't have a strong understanding of Linux internals, thoughts?

I use Ubuntu (Trusty and Xenial) and usually put my computer in sleep mode rather than power it down. A common problem is that on wake the network manager is down so one has to restart the service. E.g.

sudo service network-manager restart

I am tired of doing this so I have hacked this together:

#!/bin/sh

# should live in /lib/systemd/system-sleep/...
# sudo mv restart-network-on-wake.sh /lib/systemd/system-sleep/
# sudo chmod a+x /lib/systemd/system-sleep/restart-network-on-wake.sh

case $1/$2 in
    pre/*)
        echo "Going to $2..."
        exit 0
        ;;
    post/*)
        echo "Waking up from $2..."
        if ! ping -q -c 1 -W 1 8.8.8.8 > /dev/null; then
            echo "IPv4 is down, restarting network-manager"
            service network-manager restart
        fi
        ;;
esac

I am a novice at shell scripting I guess and don't have a strong understanding of Linux internals. Do you have any thoughts?

Source Link
Loading