[CentOS] How to schedule for a repeated task?
MHR
mhullrich at gmail.com
Sat May 1 16:26:27 UTC 2010
On Sat, May 1, 2010 at 2:52 AM, hadi motamedi <motamedi24 at 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
More information about the CentOS
mailing list