0

I want to log in to user2 via bash script, so my script contains:

sudo -i -u user2

Also I don't want to enter my sudo password by hands. Before I did something like this:

echo "my_sudo_password" | sudo -S <command> 

but if I am trying it in this case:

echo "my_sudo_password" | sudo -S -i -u user2

I have error

-sh: 1: my_sudo_password: not found

Can you answer what am I doing wrong?

Leo
  • 1

1 Answers1

0

If lack of security doesn't bother you, you can try this:

coproc ( sleep 2; xdotool key your_password key Return )
sudo -i -u user2

which simulates your doing it by hand. The sleep wait time can be adjusted to suit your situation.