I need to read the listing of a remote directory using ssh in a shell script. I'm using expect and the code that I tried is
#!/bin/expect
spawn ssh user@server 'ls -t path | head -1' > dir.txt
expect 'Password:*'
send "Password\n"
The result is that no file is created. But if I run the same command on the shell it works
ssh user@server 'ls -t path | head -1' > dir.txt