Dear All I need to schedule for a repeated task on my CentOS server, as the followings: -) Telnet to a remote node -) Issue a command -) Capture the output in a log -) Logout from Telnet -) Wait for a prescribed time interval -) Then redo , but append the subsequent output in just on file Can you please let me know which options do we have to write such a task? Thank you
On Sat, May 1, 2010 at 10:10 AM, hadi motamedi motamedi24@gmail.com wrote:
Dear All I need to schedule for a repeated task on my CentOS server, as the followings: -) Telnet to a remote node -) Issue a command -) Capture the output in a log -) Logout from Telnet -) Wait for a prescribed time interval -) Then redo , but append the subsequent output in just on file Can you please let me know which options do we have to write such a task? Thank you
Use cron to schedule the tasks.
if you need to automate an interactive command you can use expect [1][2]
[1] http://expect.nist.gov/ [2] http://en.wikipedia.org/wiki/Expect
HTH
if you need to automate an interactive command you can use expect [1][2]
Thank you for your reply. I am trying like the followings:
#expect
set name 172.16.17.160 set user id set password pwd set cmd1 "cd /tmp" set cmd2 "cp log.cap /export/home" set cmd3 "logout" spawn telnet $name expect "login:" send "$user" expect "Password:" send "$password" send "$cmd1" send "$cmd2" send "$cmd3" exit
I don't see any error when executing, but at the end no file is being copied. Can you please correct me? Thank you
On Sat, May 1, 2010 at 5:52 AM, hadi motamedi motamedi24@gmail.com wrote:
Thank you for your reply. I am trying like the followings: #expect
set name 172.16.17.160 set user id set password pwd set cmd1 "cd /tmp" set cmd2 "cp log.cap /export/home" set cmd3 "logout" spawn telnet $name expect "login:" send "$user" expect "Password:" send "$password" send "$cmd1" send "$cmd2" send "$cmd3" exit
Several things are wrong with this:
1. DO NOT EVER USE TELNET. Seriously. Don't do this. It sends your user/pass in plain text. It's a horrendous security risk. I don't care what excuse you have to try to defend it. DO NOT DO IT. Use ssh keys instead.
2. Use ssh keys instead of setting a password in the script.
3. You don't need to use expect to set the PWD to /tmp. You can do this with basic scripting. Pick up a bash scripting guide and read through it. I see almost nothing in your example that requires expect. This can be done with a simple bash script.
DO NOT EVER USE TELNET.
Use ssh keys instead of setting a password in the script.
You don't need to use expect to set the PWD to /tmp. You can do
this with basic scripting. Pick up a bash scripting guide and read through it. I see almost nothing in your example that requires expect. This can be done with a simple bash script.
Thank you for your reply. Please be informed that the remote node is a
VxWorks node that currently does not support ssh. Actually I need to telnet to it and issue some commands and capture the output of the commands in a file and then wait for a prescribed time interval and then redo from the start (but I need to append all of the logs in just one file). I want to automate this procedure. Please help me.
From: hadi motamedi motamedi24@gmail.com
Actually I need to telnet to it and issue some commands and capture the output of the commands in a file and then wait for a prescribed time interval and then redo from the start (but I need to append all of the logs in just one file).
Maybe have a look at nc (man nc)...
JD
On Mon, May 03, 2010 at 12:02:43PM +0100, hadi motamedi wrote:
Thank you . It can connect to remote node port 23. But how can I send
command to remote node and capture its log?
Do you do a single iota of research on your own or do you expect the members of this list to do *everything* for you?
There are man pages ("man nc"); documentation (located in /usr/share/doc/nc-1.84) and google.
Can you please make an effort to help yourself on occasion? You will learn more and you won't alienate members of the list.
I'm extremely sorry if this comes across as rude, but quite frankly I find your lack of research and your wasting the time of the readers of this list quite rude.
John
Do you do a single iota of research on your own or do you
expect the members of this list to do *everything* for you?
Sorry for wrong question. I just need to know if you see implementing it
via 'expect' or 'nc' is feasible or not? I you see it feasible, I will extract the details by myself.Please let me know.
hadi motamedi wrote:
Do you do a single iota of research on your own or do you expect the members of this list to do *everything* for you?
Sorry for wrong question. I just need to know if you see implementing it via 'expect' or 'nc' is feasible or not? I you see it feasible, I will extract the details by myself.Please let me know.
The nature of unix tools is that you can make about anything work if you use the shell to glue in missing functionality with some other tool. nc by itself would be better at bulk network transfers while expect would be better at interactive chatting where you need to parse the output from the other side. With perl's Net::Telnet module you'd have a good tool for the chat plus a complete programing language around it.
But, I'll repeat the advice to use something based on ssh if the other end is a computer - and if you are moving files around, use rsync over ssh.
Several things are wrong with this:
- DO NOT EVER USE TELNET.
Seriously. Don't do this. It sends your user/pass in plain text. It's a horrendous security risk. I don't care what excuse you have to try to defend it. DO NOT DO IT. Use ssh keys instead.
I agree but some devices doesn't support ssh such as Routers, Embedded systems.
On Sat, May 01, 2010 at 07:12:54AM -0400, Jim Perrin (jperrin@gmail.com) wrote:
On Sat, May 1, 2010 at 5:52 AM, hadi motamedi motamedi24@gmail.com wrote:
[snip]
Several things are wrong with this:
- DO NOT EVER USE TELNET.
<just to be picky ;-)>
While I 100% agree with this you need to refine the wording a little
- DO NOT EVER USE TELNET TO LOGIN.
Telnet is still a VERY VERY worthy tool to debug e.g. a mail/imap/pop/whatever conection and I would not want to live without it, even for HTTP connections, the only thing you need to know is the protocol you want to debug.
telnet mail.domain.ext 25
If you establish a sucessful connection you will see something like Connected to mail.domain.ext. Escape character is '^]'. 220 domain.ext ESMTP MDaemon 6.7.6; Tue, 25 Mar 2003 11:37:02 +0000
The next step is to tell the mail server where you are mailing from. This is the FQDN or the IP address of your local machine HELO local.domain.name
A well configured mail server will check you are who you say you are (so, if you lie about your machine FQDN or IP, you may well caught), then respond 250 mail.domain.ext Hello local.domain.name [a.b.c.d], pleased to meet you
Next you specify who the mail is from MAIL FROM: mail@domain.ext
which should return 250 2.1.0 mail@domain.ext... Sender ok
Some mail servers will check that the domain you use in the MAIL FROM: command exists.
Now tell the mail server who the email is to RCPT TO: mail@destinationdomain.ext
which should return 250 2.1.0 mail@destinationdomain.ext... Recipient ok
Now tell the mail server that you are going to send the email DATA
Now you can start writing your email. Start by entering the email headers. Note the space between the : terminating the header name and the value. This is mandatory. From: Your Name To: Their name CC: Someone else Subject: Your subject.
Once you finished with your header, press enter to leave a blank line before you begin the message body, then enter your email contents. To tell the mail server that you have completed the message enter a single "." on a line on its own.
The mail server should reply with something like 250 2.0.0 OK Message saved for delivery
You should close the connection by issuing the QUIT command. The mailserver should sign off with something like: 221 2.0.0 mail.domain.ext closing connection Connection closed by foreign host.
</just to be picky ;-)>
Jobst
Seriously. Don't do this. It sends your user/pass in plain text. It's a horrendous security risk. I don't care what excuse you have to try to defend it. DO NOT DO IT. Use ssh keys instead.
Use ssh keys instead of setting a password in the script.
You don't need to use expect to set the PWD to /tmp. You can do
this with basic scripting. Pick up a bash scripting guide and read through it. I see almost nothing in your example that requires expect. This can be done with a simple bash script.
-- During times of universal deceit, telling the truth becomes a revolutionary act. George Orwell _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
On Sat, May 1, 2010 at 2:52 AM, hadi motamedi motamedi24@gmail.com wrote:
if you need to automate an interactive command you can use expect [1][2]
Thank you for your reply. I am trying like the followings: #expect
set name 172.16.17.160 set user id set password pwd set cmd1 "cd /tmp" set cmd2 "cp log.cap /export/home" set cmd3 "logout" spawn telnet $name expect "login:" send "$user" expect "Password:" send "$password" send "$cmd1" send "$cmd2" send "$cmd3" exit
I don't see any error when executing, but at the end no file is being copied. Can you please correct me? Thank you
Aside from the security/telnet issues, here's my take:
1) You don't need to cd to /tmp to copy a file out of it.
2) You don't verify the existence of the file before copying it.
3) You don't log what happens if the file doesn't exist.
4) I don't see anything to do the appending you mentioned in the first email that you wanted done.
As others have already pointed out, this can be done with a simple bash script, even if you do use telnet. I'd suggest getting a good bash reference and learning it, or perl for a more robust interface.
HTH
mhr
As others have already pointed out, this can be done with a simple
bash script, even if you do use telnet. I'd suggest getting a good bash reference and learning it, or perl for a more robust interface.
Thank you for your reply. From your first message regarding using expect to
do the job , I tried to get more familiar with expect so I sent you my first expect script to see if I have correctly understood it. Actually, my intended expect script must be something like the followings : #for i in 1 2 3 4 5 6 7 8 9 10 do /usr/bin/expect
set name 172.16.17.160 set cmd1 "command1" set cmd2 "logout" spawn telnet $name send "$cmd1" send "$cmd2" exit
sleep 500 done I want to capture the output of issuing the 'command1' on the remote node into a text file , and also append the subsequent outputs into just one file. As you see, the remote node accepts anonymous login so no need to supply user id & pwd. I just need to issue the 'command1' on it and capture the output and then wait for a prescribed time interval and then redo from the start. Please correct me on any mis-understanding.
hadi motamedi wrote:
if you need to automate an interactive command you can use expect [1][2]
Thank you for your reply. I am trying like the followings: #expect
set name 172.16.17.160 set user id set password pwd set cmd1 "cd /tmp" set cmd2 "cp log.cap /export/home" set cmd3 "logout" spawn telnet $name expect "login:" send "$user" expect "Password:" send "$password" send "$cmd1" send "$cmd2" send "$cmd3" exit
that cp command is executed on the remote system, so it will copy your log.cap file to /export/home on the remote system. is that what you want to do?
hadi motamedi wrote:
Dear All I need to schedule for a repeated task on my CentOS server, as the followings: -) Telnet to a remote node -) Issue a command -) Capture the output in a log -) Logout from Telnet -) Wait for a prescribed time interval -) Then redo , but append the subsequent output in just on file Can you please let me know which options do we have to write such a task? Thank you
If the remote end of this is some dumb device that can only do telnet, use expect, kermit, or perl's Net::Telnet module to chat with it. If it is another computer, set up ssh keys and just run remote commands directly. And use cron to schedule the runs.
On Sat, May 1, 2010 at 10:52 AM, Les Mikesell lesmikesell@gmail.com wrote:
hadi motamedi wrote:
Dear All I need to schedule for a repeated task on my CentOS server, as the followings: -) Telnet to a remote node -) Issue a command -) Capture the output in a log -) Logout from Telnet -) Wait for a prescribed time interval -) Then redo , but append the subsequent output in just on file Can you please let me know which options do we have to write such a task? Thank you
If the remote end of this is some dumb device that can only do telnet, use expect, kermit, or perl's Net::Telnet module to chat with it. If it is another computer, set up ssh keys and just run remote commands directly. And use cron to schedule the runs.
Yah, perl would be easiest:
use Net::Telnet (); $username = "fred"; $passwd = "fredspassword";
$server = new Net::Telnet (Timeout => 10, Prompt => '/\[fred\@vm\-helios-005 \~\]\$/'); $server->open("vm-helios-005"); $server->login($username, $passwd); @lines = $server->cmd("hostname "); print @lines;
That's almost unchanged from the example in cpan's Net::Telnet.. :)
On Sat, May 01, 2010 at 10:10:49AM +0100, hadi motamedi wrote:
Study up on 'vron' and 'crontab'.
////jerry
Dear All I need to schedule for a repeated task on my CentOS server, as the followings: -) Telnet to a remote node -) Issue a command -) Capture the output in a log -) Logout from Telnet -) Wait for a prescribed time interval -) Then redo , but append the subsequent output in just on file Can you please let me know which options do we have to write such a task? Thank you
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos