Quantcast
Channel: How to su non-interactively? - Server Fault
Viewing all articles
Browse latest Browse all 3

Answer by tonioc for How to su non-interactively?

$
0
0

You could either use the echo :

echo <otherpwd> | su - otheruser -c "my command line"

or expect:

expect -c 'spawn su - otheruser -c "my command line"; expect "Password :"; send "<otherpwd>\n"; interact'

But this means the password is stored as cleartext in your script, which is never a good thing. Really, sudo would be the best way to go ...


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>