1

I'm trying to do a two-lines-script to temporary set a specific nameserver. Therefore I just output 'nameserver XXX.XXX.XXX.XXX' to the /etc/resolv.conf file, because it gets overwritten next time anyways. The thing is, when I try to ask for the password via gksudo, I get an error because it tries to output the gksudo result to the file.

UPDATE:

My current file is now:

#!/bin/sh
gksudo "bash -c \"echo 'nameserver XXX.XXX.XXX.XXX' >> /etc/resolv.conf\""

The command with sudo instead of gksudo and without the "" and \\ works as it should. Remains how to get it into the GUI prompt.

3 Answers3

3

You were very close, try that:

#!/bin/sh
gksudo "bash -c \"echo 'nameserver XXX.XXX.XXX.XXX' >> /etc/resolv.conf\""
chaos
  • 27,506
  • 12
  • 74
  • 77
1

As you can read here - http://sernaonubuntu.wikidot.com/command-line:piping-and-directing-output the >> symbol appends the result of the command to the file

The result of 'nameserver XXX.XXX.XXX.XXX' command is.. well command not found :P

What comes to the rescue is the echo command (as @chaos rightfully said) which echoes the text and that result can be piped to the file

Though you can use a simpler version of his script

#!/bin/sh
gksudo echo 'nameserver XXX.XXX.XXX.XXX' >> /etc/resolv.conf
Rishabh
  • 128
-4

Have you tryed this in sted type in this:

    #!bin/sh
           Case (nameserver) in
                 /bin/sh
                 nameserver = XXX.XXX.XXX XXX >>
                 gksudo 'echo' nameserver >>
                 resolvconf XXX.XXX.XXX.XXX >>
           endl

and it might work fine this way.

Michael
  • 2,499
  • 5
  • 19
  • 24