FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 05-01-2010, 11:12 AM
Jim Perrin
 
Default How to schedule for a repeated task?

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.




--
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
 
Old 05-01-2010, 11:44 AM
hadi motamedi
 
Default How to schedule for a repeated task?

1. DO NOT EVER USE TELNET.



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.








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.



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-01-2010, 02:52 PM
Les Mikesell
 
Default How to schedule for a repeated task?

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.

--
Les Mikesell
lesmikesell@gmail.com
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-01-2010, 02:56 PM
Athmane Madjoudj
 
Default How to schedule for a repeated task?

>
> 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.
>

I agree but some devices doesn't support ssh such as Routers, Embedded systems.


--
Athmane Madjoudj
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-01-2010, 04:26 PM
MHR
 
Default How to schedule for a repeated task?

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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-01-2010, 05:40 PM
John R Pierce
 
Default How to schedule for a repeated task?

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?


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-01-2010, 06:04 PM
Kwan Lowe
 
Default How to schedule for a repeated task?

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..
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-01-2010, 10:57 PM
Jerry McAllister
 
Default How to schedule for a repeated task?

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

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-02-2010, 04:56 AM
hadi motamedi
 
Default How to schedule for a repeated task?

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.



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 05-02-2010, 04:57 AM
hadi motamedi
 
Default How to schedule for a repeated task?

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?





No, actually I wanted to copy remote node /tmp/log.cap to its /export/home. Please correct me.
Thank you



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 02:33 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org