How to view bash history executed by PC1 on PC2 by way of Ant sshexec
there are currently 2 PCs, PC1 and PC2. I have an Ant script on PC1, the script will execute bash commands on PC2 using sshexec task, the snippet may like the following:
<sshexec
host="${IPofPC2}"
username="${USERofPC2}"
password="${PASSofPC2}"
command='echo "Hello World!"'
trust="true"></sshexec>
in practice the command is a complex one, I give echo "Hello World!"
for an example.
I want to see what exactly the command is that have executed on PC2, but I don't know how to.
I googled a开发者_如何学编程nd find .bash_history
will save the remotely executed commands by one login using ssh-like terminal.
It seems this may help, but tried with no success, the .bash_history
file won't record commands executed by sshexec task remotely.
So SOS, please help. Thanks in advance.
Edit:
#/etc/syslog.conf
!sshd
*.* /var/log/sshd.log
Attachment:
$cat /var/log/sshd.log
Dec 8 17:36:29 brownshen launchproxy[1373]: /usr/libexec/sshd-keygen-wrapper: Connection from: 10.224.105.186 on port: 4090 Dec 8 17:36:30 brownshen sshd[1376]: in pam_sm_authenticate(): Failed to determine Kerberos principal name. Dec 8 17:36:30 brownshen sshd[1374]: Accepted keyboard-interactive/pam for zhouvega from 10.224.105.186 port 4090 ssh2 Dec 8 17:36:30 brownshen com.apple.SecurityServer[23]: Session 0x3096eb created Dec 8 17:36:30 brownshen com.apple.SecurityServer[23]: Session 0x3096eb attributes 0x20 Dec 8 17:36:30 brownshen com.apple.SecurityServer[23]: Session 0x3096eb dead Dec 8 17:36:30 brownshen com.apple.SecurityServer[23]: Killing auth hosts Dec 8 17:36:30 brownshen com.apple.SecurityServer[23]: Session 0x3096eb destroyed
Take a look at this: http://www.unix.com/unix-advanced-expert-users/4722-ssh-command-logging.html
My first thought was that you could change the shell specified in passwd to be a shell-wrapper that logs all input, but I think the sshd approach is better.
And, unless you have a good reason to (user input?) you should use SSH keys for auto-logins instead of saving passwords.
You will need to make sure that your script is actually being executed by Bash and not sh
. Then, add these to the beginning of your script:
HISTFILE=$HOME/.bash_history
set -o history
Choose a different file to save the history separately from the user's interactive history. You can use set -o history
to turn history saving on and set +o history
to turn it off. You can use this selectively to only save parts of the script.
Add this at the end of your script to write the in-memory history to the file:
history -w
Note that the HISTSIZE
variable affects how many lines of history are stored in memory. The default is 500 which could be quickly filled by an executing script. The HISTFILESIZE
variable also defaults to 500 and the same issue applies. You may need to set these variables to larger values in your script and set HISTFILESIZE' also in the user's startup file (e.g.
~/.bashrc`) so it doesn't get truncated during interactive use if you're using the same history file.
Note that for some uses, instead of using history you can use set -x
to turn on tracing and capture stdout to a file.
精彩评论