7

I trying run a script without become the su user and I use this command for this:

echo "password" | sudo -S <command>

If I use this command for "scp", "mv", "whoami" commands, the command works very well but when I use for "chmod", the command asks for password for my user. I don't enter password and the command works. My problem is the system asks password to me. I don't want the system asks for password.

Problem ss is like this:

[myLocalUser@myServer test-dir]$ ls -lt
total 24
--wx-wx-wx 1 root root 1397 May 26 12:12 file1
--wx-wx-wx 1 root root  867 May 26 12:12 script1
--wx-wx-wx 1 root root 8293 May 26 12:12 file2
--wx-wx-wx 1 root root 2521 May 26 12:12 file3

[myLocalUser@myServer test-dir]$ echo "myPassw0rd" | sudo -S chmod 111 /tmp/test-dir/*
[sudo] password for myLocalUser: I DONT WANT ASK FOR PASSWORD

[myLocalUser@myServer test-dir]$ ls -lt
total 24
---x--x--x 1 root root 1397 May 26 12:12 file1
---x--x--x 1 root root  867 May 26 12:12 script1
---x--x--x 1 root root 8293 May 26 12:12 file2
---x--x--x 1 root root 2521 May 26 12:12 file3

1 Answer 1

4

sudo prints this prompt on stderr prior to reading the piped password. Redirect standard error to avoid seeing it:

echo "password" | sudo -S command 2> /dev/null

You must log in to answer this question.

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