Skip to content

Commit

Permalink
Now you can use your favorite script without bash
Browse files Browse the repository at this point in the history
Also used `printf` to avoid `echo` mess
  • Loading branch information
Artoria2e5 committed Oct 25, 2015
1 parent db411bf commit d30cffc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions chnroutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ def generate_ovpn(metric):
def generate_linux(metric):
results = fetch_ip_data()
upscript_header=textwrap.dedent("""\
#!/bin/bash
#!/bin/sh
export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
OLDGW=`ip route show | grep '^default' | sed -e 's/default via \\([^ ]*\\).*/\\1/'`
OLDGW=$(ip route show | grep '^default' | sed -e 's/default via \\([^ ]*\\).*/\\1/')
if [ $OLDGW == '' ]; then
if [ "$OLDGW" == '' ]; then
exit 0
fi
if [ ! -e /tmp/vpn_oldgw ]; then
echo $OLDGW > /tmp/vpn_oldgw
printf '%s\n' "$OLDGW" > /tmp/vpn_oldgw
fi
""")

downscript_header=textwrap.dedent("""\
#!/bin/bash
#!/bin/sh
export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
OLDGW=`cat /tmp/vpn_oldgw`
OLDGW=$(cat /tmp/vpn_oldgw)
""")

Expand Down Expand Up @@ -73,7 +73,7 @@ def generate_mac(metric):
OLDGW=`netstat -nr | grep '^default' | grep -v 'ppp' | sed 's/default *\\([0-9\.]*\\) .*/\\1/'`
if [ ! -e /tmp/pptp_oldgw ]; then
echo "${OLDGW}" > /tmp/pptp_oldgw
printf '%s\n' "$OLDGW" > /tmp/pptp_oldgw
fi
dscacheutil -flushcache
Expand Down

0 comments on commit d30cffc

Please sign in to comment.