3
1
This is my simple bash:
cat test.sh
#!/bin/bash
echo "hello"
su - root -c /path/to/script.sh <<EOF
password
EOF
whoami
echo "good bye"
But I get this error:
./test.sh
hello
su: must be run from a terminal
<current-user>
good bye
(OR)
cat test2.sh
#!/bin/bash
echo "hello"
sudo su <<EOF
password
EOF
whoami
echo "good bye"
Again another error
(OR)
cat test3.sh
#!/bin/bash
echo "hello"
su root <<EOF
password
EOF
whoami
echo "good bye"
again error...
when I try:
#!/bin/bash
echo "hello"
sudo -s <<EOF
<password>
echo Now I am root
id
echo "yes!"
EOF
whoami
echo "good bye"
Then the output is:
./script.sh
hello
[sudo] password for <user>:
I also changed my script to:
#!/usr/bin/expect -f
spawn sudo -s <<EOF
expect "assword for user:"
send -- "password\r"
expect eof
and output is:
spawn sudo -s <<EOF
[sudo] password for user:
/bin/bash: <<EOF: command not found
Also which sh
output is /bin/sh
How can I resolve the error in these three scripts?
I didn't got
su user <
new syntax? – MLSC – 2014-02-18T17:25:08.230see my update...the error occurs – MLSC – 2014-02-18T17:28:57.997
don't work..I'm afraid – MLSC – 2014-02-18T17:44:41.340
@MortezaLSC And yet it's funny, because it does work on my systems Debian, Kubuntu, Arch Linux. You must have copied something wrong. – MariusMatutiae – 2014-02-18T18:14:52.137
you mean I use your heredoc solution? – MLSC – 2014-02-18T18:15:34.123