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.

0

3 Answers 3

3

You were very close, try that:

#!/bin/sh
gksudo "bash -c \"echo 'nameserver XXX.XXX.XXX.XXX' >> /etc/resolv.conf\""
3
  • Unfortunately, gksudo takes the -c now as one of its options. :-/ Jan 13, 2015 at 16:09
  • @PeterNerlich I edited the answer, please try again
    – chaos
    Jan 13, 2015 at 18:07
  • Well, it does now kind of what it should, it only somehow fails without returning an error... It works with sudo and without the "" and \\ all around, but gksudo won't. Strange... Jan 13, 2015 at 19:52
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
-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.

2
  • Which syntax is this? Surely not any shell?
    – Rmano
    Jan 13, 2015 at 15:43
  • @Rmano same language as this one.
    – muru
    Jan 13, 2015 at 15:44

Not the answer you're looking for? Browse other questions tagged .