0

I have a little bash script to run, but it appears to stop without errors on the second line:

export REQUIRE_TRIGGER=0
sudo -s -H
killall ptpd ntpd
nice -n -19 ptpd -gGW -b eth0 -s2 -i NTP -t -c D 

The script is in a file. What am I missing?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Levi
  • 301
  • 3
  • 12
  • 1
    You're missing that `killall` won't be run until `sudo` finishes and exits. – Charles Duffy Jul 18 '17 at 20:15
  • The script is inside a file. – Levi Jul 18 '17 at 20:21
  • Yes, you included the commands you want `sudo` to run in the file, but you didn't do anything to cause them to be fed to stdin of the shell `sudo` starts. So that shell is still trying to read from the script's original stdin, **not** reading the commands later in the script. – Charles Duffy Jul 18 '17 at 20:22
  • ...which is to say: `bash somescript` is **not at all** the same thing as `bash – Charles Duffy Jul 18 '17 at 20:25
  • (Adding the fact that "the script is in a file" to your question does not make this any less duplicative; the other answers still apply just as much as they did pre-edit). – Charles Duffy Jul 18 '17 at 20:26
  • What is the safe solution? – Levi Jul 18 '17 at 20:26
  • A heredoc, as described in the linked questions' answers, or to escalate each command individually, as your current answer suggests. Heredocs aren't safe *for passwords*, but if they're just containing script content, that's a very standard use. – Charles Duffy Jul 18 '17 at 20:27
  • (If you want to allow the current user to run those explicit commands without entering any password, you can put that configuration in `/etc/sudoers`). – Charles Duffy Jul 18 '17 at 20:28

1 Answers1

1

try to do

    sudo killall ptpd ntpd
    sudo nice -n -19 ptpd -gGW -b eth0 -s2 -i NTP -t -c D 
Camden
  • 283
  • 2
  • 15