Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在linux中远程运行history命令_Linux_Unix - Fatal编程技术网

在linux中远程运行history命令

在linux中远程运行history命令,linux,unix,Linux,Unix,我的要求是通过在远程服务器上运行以下命令,将命令的历史记录保存到名为history_yymdd.txt的文件中 history > history_20170523.txt 我尝试使用以下命令,但它在远程服务器10.12.13.14上创建了一个空白文件 ssh 10.12.13.14 "history > history_20170523.txt" 当我登录到远程服务器并运行history命令时,文件创建成功。但是我需要在20台服务器上运行这个命令,所以创建一个脚本在每台服务器上

我的要求是通过在远程服务器上运行以下命令,将命令的历史记录保存到名为history_yymdd.txt的文件中

history > history_20170523.txt
我尝试使用以下命令,但它在远程服务器10.12.13.14上创建了一个空白文件

ssh 10.12.13.14 "history > history_20170523.txt"
当我登录到远程服务器并运行history命令时,文件创建成功。但是我需要在20台服务器上运行这个命令,所以创建一个脚本在每台服务器上远程运行它是我的目标


提前感谢。

您的操作方式不对,而且远程计算机没有用户。正确的做法是 ssh-q-ttuser@10.12.13.14'history>history_20170523.txt'

“history”命令转储.bash_历史的内容,因此这可能对您有用

更优雅的解决方案可能是:

scp user@machine_name:~/.bash_history history_20170523.txt

哦,糟糕,我没注意到他想做什么。我只关注ssh部分,ssh命令没有正确调用。感谢Chris的帮助。知道为什么history命令不起作用吗?ssh会话不是交互式的,因此它不会加载您的历史记录或启用其他交互式功能。这在Bash手册中有详细说明。@veera-如果你喜欢这个答案,请投票并接受它
scp user@machine_name:~/.bash_history history_20170523.txt