0

Now I want to record all user's login messages in freeBSD, so I type last -f /var/log/utx.log in freeBSD to see the log.

The output format is: brandboat pts/1 xxx.xxx.xxx.xxx Sat Nov 1 11:28 still logged in brandboat pts/0 xxx.xxx.xxx.xxx Sat Nov 1 11:21 still logged in root ttyv0 Sat Nov 1 11:16 still logged in brandboat pts/1 xxx.xxx.xxx.xxx Sat Nov 1 11:11 - 11:25 (00:13)

And I try to copy all of these message in to a variable: set aaa= `last -f /var/log/utx.log` echo $aaa

the output is:

brandboat pts/1 xxx.xxx.xxx.xxx Sat Nov 1 11:28 still logged in brandboat pts/0 xxx.xxx.xxx.xxx Sat Nov 1 11:21 still logged in root ttyv0 Sat Nov 1 11:16 still logged in brandboat pts/1 xxx.xxx.xxx.xxx Sat Nov 1 11:11 - 11:25 (00:13)

As you can see, it doesn't keep the original format from the command output. How do I keep it in csh?

brandboat
  • 195
  • 1
  • 1
  • 9

1 Answers1

0

This is black magic but it works:

$ csh
% set g=`ls | sed -s ':a;N;$\\!ba;s/\n/\\n/g'`
% echo "$g"
% /bin/echo -e "$g"

The idea is to change the newlines by \n using sed. I used this trick to get it. Note that I had to double escape label !ba to tell csh that it is not an event.

You may replace ls by last -f /var/log/utx.log to check if it works for you.

Community
  • 1
  • 1
Edouard Thiel
  • 5,878
  • 25
  • 33