linux中,怎样通过重定向的方法将命令在另一个终端中运行?

linux中,怎样通过重定向的方法将命令在另一个终端中运行?,第1张

远程执行命令?

利用spawn和expect登录,send发送指令就可以了。

http://blog.sina.com.cn/s/blog_5140741f01015w3j.html

可以参考下上面的链接

鸟哥在书中介绍了这样的一种环境。公室内有10台Linux主机,每一台负责一个网络服务。为了无需登录每台主机去查看登录文件,需要设置一台syslog服务器,其他主机的登录文件都发给它。这样做的话,只需要登录到syslog服务器上就能查看所有主机的登录文件。RedHat上的设置方法,鸟哥已经介绍了。【服务器端】step1:查看服务器是否开启了UDP514端口grep'514'/etc/servicesstep2:修改syslogd的启动设置文件/etc/sysconfig/syslog将SYSLOGD_OPTIONS="-m0"修改成SYSLOGD_OPTIONS="-m0-r"step3:重启syslogd服务/etc/init.d/syslogrestart重启后,你会发现UDP514端口已经打开。ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programnameudp000.0.0.0:5140.0.0.0:*5628/syslogd【客户端】step1:在/etc/syslog.conf中,添加下行。user.*@192.168.0.Y#syslog服务器的IP地址在Ubuntu中配置syslogd服务器的方法类似。step1:查看服务器是否开启了UDP514端口,有下面一行说明端口514被打开,没有需要加入#grep'514'/etc/services184:shell514/tcpcmd#nopasswordsused185:syslog514/udpstep2:修改/etc/init.d/sysklogd,将SYSLOGD=""修改成SYSLOGD="-r"step3:修改/etc/default/syslogd,将SYSLOGD=""修改成SYSLOGD="-r"step4:重启服务/etc/init.d/sysklogdrestartstep5:验证在/var/log/messages中找到May123:31:59flagonxia-desktopsyslogd1.5.0#5ubuntu3:restart(remotereception)#netstat-tlunp得到syslogd服务正在监听端口514udp000.0.0.0:5140.0.0.0:*3912/syslogdstep6:假设syslog服务器的IP地址:192.168.1.25,在其他主机上的/etc/syslog.conf中加入*.*@192.168.1.25注:/etc/syslog.conf文件的解析日志文件按/etc/syslog.conf配置文件中的描述进行组织。下图是/etc/syslog.conf文件的内容:[root@localhost~]#cat/etc/syslog.conf#Logallkernelmessagestotheconsole.#Loggingmuchelsecluttersupthescreen.#kern.*/dev/console#Loganything(exceptmail)oflevelinfoorhigher.#Don'tlogprivateauthenticationmessages!*.infomail.noneauthpriv.nonecron.none/var/log/messages#Theauthprivfilehasrestrictedaccess.authpriv.*/var/log/secure#Logallthemailmessagesinoneplace.mail.*-/var/log/maillog#Logcronstuffcron.*/var/log/cron#Everybodygetsemergencymessages*.emerg*#Savenewserrorsoflevelcritandhigherinaspecialfile.uucp,news.crit/var/log/spooler#Savebootmessagesalsotoboot.loglocal7.*/var/log/boot.logsyslog.conf行的基本语法是:[消息类型][处理方案]注意:中间的分隔符必须是Tab字符!消息类型是由"消息来源"和"紧急程度"构成,中间用点号连接。例如上图中,news.crit表示来自news的“关键”状况。在这里,news是消息来源,crit代表关键状况。通配符*可以代表一切消息来源。说明:第一条语句*.info,将info级以上(notice,warning,err,crit,alert与emerg)的所有消息发送到相应日志文件。日志文件类别(按重要程度分类)日志文件可以分成八大类,下面按重要性从大到下列出:emergemergency,紧急alert警报critcritical,关键errerror,错误warning警告notice通知info信息debug调试简单列一下消息来源auth认证系统,如login或su,即询问用户名和口令cron系统执行定时任务时发出的信息daemon某些系统的守护程序的syslog,如由in.ftpd产生的logkern内核的信息lpr打印机的信息mail处理邮件的守护进程发出的信息mark定时发送消息的时标程序news新闻组的守护进程的信息user本地用户的应用程序的信息uucpuucp子系统的信息*表示所有可能的信息来源处理方案"处理方案"选项可以对日志进行处理。可以把它存入硬盘,转发到另一台机器或显示在管理员的终端上。处理方案一览:文件名写入某个文件,要注意绝对路径。@主机名转发给另外一台主机的syslogd程序。@IP地址同上,只是用IP地址标识而已。/dev/console发送到本地机器屏幕上。*发送到所有用户的终端上。|程序通过管道转发给某个程序。例如:kern.emerg/dev/console(一旦发生内核的紧急状况,立刻把信息显示在控制台上)说明:如果想修改syslogd的记录文件,首先你必须杀掉syslogd进程,在修改完毕后再启动syslogd。攻击者进入系统后通常立刻修改系统日志,因此作为网管你应该用一台机器专门处理日志信息,其他机器的日志自动转发到它上面,这样日志信息一旦产生就立刻被转移,这样就可以正确记录攻击者的行为。

向Linux登录终端发消息

原创 2013年02月17日 18:00:09 1600

同一台服务器,可能有很多个用户登录在上面,每个用户都是一个系统终端,可以向其他终端发送消息,同在服务器上开发的开发人员可以简单的互动(不能回复)一下哈!

一,效果

先登录一个终端,如下:

[html] view plain copy

[root@localhost /]# who

root tty1 2013-02-16 18:14 (:0)

root pts/02013-02-17 02:01 (:0.0)

[root@localhost /]#

登录的终端为pts/0。然后再打开一个终端,如下:

[html] view plain copy

[root@localhost /]# who

root tty1 2013-02-16 18:14 (:0)

root pts/02013-02-17 02:01 (:0.0)

root pts/12013-02-17 02:02 (:0.0)

[root@localhost /]#

此时登录的终端为pts/1。现在假设pts/1发消息给pts/0。

[html] view plain copy

[root@localhost /]# write root pts/0

hello

在pts/0终端上收到消息如下:

[html] view plain copy

[root@localhost /]#

Message from [email protected] on pts/1 at 02:03 ...

hello

在pts/0上只是收到消息,不能回复的。

再看一下write命令的解释吧

NAME

write - send a message to another user

SYNOPSIS

write user [ttyname]

DESCRIPTION

Write allows you to communicate with other users, by copying lines from

your terminal to theirs.

When you run the write command, the user you are writing to gets a mes-

sage of the form:

Message from yourname@yourhost on yourtty at hh:mm ...

Any further lines you enter will be copied to the specified user’s ter-

minal. If the other user wants to reply, they must run write as well.

When you are done, type an end-of-file or interrupt character. The

other user will see the message EOF indicating that the conversation is

over.

You can prevent people (other than the super-user) from writing to you

with the mesg(1) command. Some commands, for example nroff(1) and

pr(1), may disallow writing automatically, so that your output isn’t

overwritten.

If the user you want to write to is logged in on more than one termi-

nal, you can specify which terminal to write to by specifying the ter-

minal name as the second operand to the write command. Alternatively,

you can let write select one of the terminals - it will pick the one

with the shortest idle time. This is so that if the user is logged in

at work and also dialed up from home, the message will go to the right

place.

The traditional protocol for writing to someone is that the string

‘-o’, either at the end of a line or on a line by itself, means that

it’s the other person’s turn to talk. The string ‘oo’ means that the

person believes the conversation to be over.

SEE ALSO

mesg(1), talk(1), who(1)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8971619.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-23
下一篇 2023-04-23

发表评论

登录后才能评论

评论列表(0条)

保存