我是linux和shell脚本编程的新手。我想连接到localhost并与之交互。
#! /bin/bash
(exec /opt/scripts/run_server.sh)当我执行这个bash脚本时,它开始监听一个端口。
Listening on port xxxxx现在我想发出这个命令"telnet localhost xxxxx“我尝试了这样的命令:
#! /bin/bash
(exec /opt/opencog/scripts/run_server.sh)&&
telnet localhost xxxxx它仍然在端口上侦听。但我认为第二个命令没有运行。我期待着另一个窗口显示它是这样连接的。
vishnu@xps15:~$ telnet localhost xxxx
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
server> 我将它们作为脚本执行的原因是,在服务器中,我需要通过发出诸如"scm“、"parse”等命令来自动执行某些处理。
vishnu@xps15:~$ telnet localhost xxxx
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
server>scm
Entering scheme shell; use ^D or a single . on a line by itself to exit.
guile> (parse "i eat apple")我有很多短信要发。手动我不能对每一句话都发出这个解析命令。所以我想要自动化。因此,我需要编写一个脚本来连接到服务器并进行交互。
任何指导方针。最后,如何与这个guile shell交互/发送命令?
发布于 2016-11-07 18:58:39
作为相同或不同的用户登录到linux服务器并运行一些命令或.sh脚本(对于提交后挂钩或cron作业非常有用)的一种方法是使用名为sshpass的程序,例如,cron作业命令或svn提交后挂钩将如下所示:
/usr/bin/sshpass -p 'password' /usr/bin/ssh
-o StrictHostKeyChecking=no -q user@localhost 'any command'只需将password替换为您密码,将user替换为您的用户,并将您需要作为特定用户运行的命令放入……
要在ubuntu上安装sshpass it,只需输入
apt-get install sshpass或者在CentOs上
yum install sshpass发布于 2016-11-07 20:07:01
我用netcat (nc)命令解决了这个问题。
$ echo "command1\ncommand2\n" | nc localhost xxxxx我可以使用telnet localhost xxxx手动连接到localhost,然后我可以像这样将命令从shell传递到localhost。
https://stackoverflow.com/questions/40462351
复制相似问题