LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why can't record command containing ssh into /var/log/ssh.log? (https://www.linuxquestions.org/questions/linux-newbie-8/why-cant-record-command-containing-ssh-into-var-log-ssh-log-4175616820/)

luofeiyu 11-02-2017 03:03 AM

Why can't record command containing ssh into /var/log/ssh.log?
 
Code:

vim /etc/profile
export HISTTIMEFORMAT="%Y-%m-%d:%H-%M-%S:  `whoami` : "
export PROMPT_COMMAND='history -a |grep ssh >> /var/log/ssh.log'

sudo touch /var/log/ssh.log
chmod 777 /var/log/ssh.log

Login with a normal user ,to input `cat /var/log/ssh.log` ,why no record in /var/log/ssh.log?

luofeiyu 11-02-2017 03:58 AM

export PROMPT_COMMAND='history |grep ssh >> /var/log/ssh.log'

scasey 11-02-2017 11:55 AM

Quote:

Originally Posted by luofeiyu (Post 5776163)
export PROMPT_COMMAND='history |grep ssh >> /var/log/ssh.log'

That just puts "history |grep ssh >> /var/log/ssh.log" into the environment variable PROMPT_COMMAND

To write to a file, just execute the command:
Code:

history  |grep ssh >> /var/log/ssh.log
PS. Setting perms on any file to 777 is almost never a good idea


All times are GMT -5. The time now is 07:55 PM.