1

I am trying to check user password via login command like this:

# echo "name\npassword" | login  

but the command ends without writing anything. echo ends because of SIGPIPE. Why did login stop before asking for name and password?

When I do the same with passwd command, it works:

# echo "password\npassword" | passwd  
Enter new UNIX password: 
Retype new UNIX password:
passwd: password updated successfully 

I have Ubuntu 12.04 and Bash 4.2.25

9

The login command reads input from the terminal instead of accepting it as input via pipe (STDIN).

If you want to script login you can use the expect utility:

#!/usr/bin/expect

spawn "login"

expect "login:" { send "mtak\r" }
expect "Password:" { send "mypassword\r" }

interact

Paste this in a file, run chmod +x script.ex and run it with ./script.ex

  • NICE! Thanks for this. I've been looking for an interactive solution for some other scripts and prefer expect to the boring read. +1 for sure – SaxDaddy Apr 3 '14 at 23:12

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.