I'm trying to write a script that reads logs from 3 linux machines and writes the logs (with some kind of prefix) in one file.
My problem is that I can access to the file in order to see it, but when I try to write it doesn't work.
Working code
expect -c "
spawn ssh user@x.x.x.x \" tail -f my_file\"
expect {
\"*assword\" {send \"PASS\r\";}
}
expect eof
"
if I add
tail -f >> my_file.log
it doesn't work.
First off, I would highly recommend learning how to use SSH with keys so that you don't need a password.
Then, all you need to do is this:
ssh username@server 'tail -f filename' >> my_file.log
Your command
tail -f filename >> my_file.log
is being run on the remote. So my_file.log is on the remote. To get the output to a local file, move the >> my_file.log
to the end of the expect script:
expect -c "..." >> my_file.log
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.