You are not logged in.

#1 2012-08-18 09:42:31

Rulz
Member
Registered: 2012-08-17
Posts: 3

Little error in .bashrc

Hi, i'm new in Arch, and i changed to them because i like stay always up to date. I'm really happy with Arch.

I have a little problem with the .bashrc, in this part of code:

if check_networksite "192.168.0.1"; then
            estadolan="${yellow}>> LAN Connected"
    else
            estadolan="${yellow}>> LAN Disconnected"
    fi

What can be the error there? I'm sure that the router's IP is that, but it says LAN Disconnected. Can anyone help me? Sorry for english and thanks smile

Offline

#2 2012-08-18 10:48:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Little error in .bashrc

What is check_networksite supposed to do?

Offline

#3 2012-08-18 11:25:05

javex
Member
Registered: 2011-12-30
Posts: 79

Re: Little error in .bashrc

Does check_networksite exit with code "0" if it is connected. Remember: An exit code of 0 is success while anything different is interpreted as failure. This is contrary to programming languages where 0 often means false and 1 means true.

You should give us a little more output (check_networksite and what the rest of the script does) so we can help you better.

Offline

#4 2012-08-18 12:23:49

Rulz
Member
Registered: 2012-08-17
Posts: 3

Re: Little error in .bashrc

karol wrote:

What is check_networksite supposed to do?

It checks if connected to router.

This code is part of my custom prompt.
__________        .__                     __         .__        __           
\______   \ __ __ |  |  ________        _/  |________|__| _____|  | __ ____ 
  |       _/|  |  \|  |  \___   /        \   __\_  __ \  |/  ___/  |/ // __ \
  |    |   \|  |  /|  |__ /    /          |  |  |  | \/  |\___ \|    <\  ___/
  |____|_  /|____/ |____//_____ \         |__|  |__|  |__/____  >__|_ \___  >
         \/                    \/                             \/     \/    \/

------------------------------------------------------------------------------
i686 >> 3.4.8-1-ARCH >> sáb ago 18 13:38:37 CEST 2012 >> LAN Disconnected
------------------------------------------------------------------------------

Logged in as rulz in machine archdesktop

[~]->

Anyway, thanks, using that javex said, and other helps, i made it work correctly smile

Offline

#5 2012-08-18 12:25:24

bohoomil
Banned
Registered: 2010-09-04
Posts: 2,377
Website

Re: Little error in .bashrc

Wouldn't something like this:

sudo ping -c 1 192.168.1.1 >/dev/null && echo -e Connected || echo -e Disconnected

suffice?

Edit: a bit too late...

Last edited by bohoomil (2012-08-18 12:25:54)


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#6 2012-08-18 18:42:43

Rulz
Member
Registered: 2012-08-17
Posts: 3

Re: Little error in .bashrc

Hi bohoomil. I tried that, and it request me a password. I'm not good at bash, i'm learning tongue, so i couldn't fix the error. Anyway thanks, alternative codes always are interesting smile

Offline

#7 2012-08-18 21:27:48

bohoomil
Banned
Registered: 2010-09-04
Posts: 2,377
Website

Re: Little error in .bashrc

The issue with password can be easily solved. You can either run

sudo visudo

and put a line like this in the sudoers config file:

your_username ALL=(ALL) NOPASSWD: /usr/bin/ping

Or you can set the SUID bit on the ping binary:

sudo chmod u+s /usr/bin/ping 

and run ping as a regular user (without sudo at all).


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

Board footer

Powered by FluxBB