Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 391279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:02:46+00:00 2026-05-12T16:02:46+00:00

So at work i use a vpn connection and after that i have to

  • 0

So at work i use a vpn connection and after that i have to manually set my route table so everything works, I’m trying to write a bash script which will easily distinguish between my home connection and my work connection and set the correct gateway:

#!/bin/bash

# Does the ppp0 interface exist?
cat /proc/net/dev | grep ppp0 > /dev/null
ppp_check=$?

if [ $ppp_check -ne 0 ]; then
        # I'm at home and you should set the ppp0 gateway
        ip r c default via $(ifconfig ppp0 | awk -F "P-t-P:" '{print $2}' | awk -F " " '{print $1}' | tr "\n" " " | awk '{$1=$1};1')
else
        # I'm at work so you should set my work gateway
        ip r c default via 1.1.1.1
fi

ip r a 2.2.2.2/24 dev tun0
.
.
.
ip r a 10.10.10.10/24 dev tun0

The problem is that the script always executes the code for setting the home gateway even though I’m at work and the first IF statement should be skipped.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:02:46+00:00Added an answer on May 12, 2026 at 4:02 pm

    grep will return 0 if it matches the pattern, so you need to test for $ppp-check -eq 0.

    You can simplify your test a little bit:

    if grep -q ppp0 /proc/net/dev ; then
        # I'm at home
    else
        # I'm at work
    fi
    

    “grep -q” means you don’t need to redirect the output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a reference application that I use to work through DDD issues, and
I have a couple of lines of code that work if use strict; is
At work we use a common makefile that other makefiles include (via the include
Where I work we use a set schedule to build our applications. What is
I have a website hosted with godaddy. Basically for my work I use TFS.
I know this code use to work, I must have accidentally changed something when
dblink does not seem to work when I use a named connection to a
I use Silex Frame Work and I am trying to delete files in backend
I'm finally set up to be able to work from home via VPN (using
I have a very unique situation. We use a Cisco Web VPN (don't know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.