hkimhkim
asked on
How to login to remote server automatically?
I need to setup a crontab on my server to login to a remote server & ftp me a file routinely without any human intervention.
I cannot use rsh, rcp, or rlogin because I cannot edit /etc/hosts on the remote server. Besides, I only have a basic user account on the remote server.
I am wondering if there is a way to run a script program written in C or sh on my server to manually send strings to login on remote server, perform tasks, and ftp a file from the remote server to my server.
I have been playing around with sprintf, system(command), etc., but no luck because the remote server generates a very long banner messages for login process. Please help!
I cannot use rsh, rcp, or rlogin because I cannot edit /etc/hosts on the remote server. Besides, I only have a basic user account on the remote server.
I am wondering if there is a way to run a script program written in C or sh on my server to manually send strings to login on remote server, perform tasks, and ftp a file from the remote server to my server.
I have been playing around with sprintf, system(command), etc., but no luck because the remote server generates a very long banner messages for login process. Please help!
When I cut and pasted the above, it didn't keep the script layout in an orderly manner. This is the same script as above, it just looks nicer now.
#!/bin/csh -f
set u=username
set p=password
while 1
ftp -in systemname << eof_ftp
us $u $p
bin
get filename
quit
eof_ftp
exit
#!/bin/csh -f
set u=username
set p=password
while 1
ftp -in systemname << eof_ftp
us $u $p
bin
get filename
quit
eof_ftp
exit
ASKER
This script only FTPs a file.
I need to perform the following tasks on the remote server:
1. Login on to the remote server
2. Choose an option from menu
3. Setup oracle parameter (. oraenv)
4. run sqlplus and SQL statement
5. wait for output
6. close sqlplus
7. ftp the output file
8. email to acknowledge completion of job.
9. log off
All these tasks need to be completed while running this script trigerred by crontab.
client system is LINUX Redhat 6.0 and the remote system is DYNIX.
Please help.
I need to perform the following tasks on the remote server:
1. Login on to the remote server
2. Choose an option from menu
3. Setup oracle parameter (. oraenv)
4. run sqlplus and SQL statement
5. wait for output
6. close sqlplus
7. ftp the output file
8. email to acknowledge completion of job.
9. log off
All these tasks need to be completed while running this script trigerred by crontab.
client system is LINUX Redhat 6.0 and the remote system is DYNIX.
Please help.
1. to do a login programatically, you need expect
2. see 1.
3. this should be in your ~/.cshrc or ~/.profile
4. see 1. or use rsh
5. done automatically by a script
6. see 1.
7. see 1. and mpass' comment
8. see 4.
9. exit
So we end up in 2 suggestions to perform all your tasks:
a. get expect and install on your client, then write a expect script to do all you need
b. try to setup rsh on the server,
you simply need to modify your ~/.rhosts, then you may try rsh from the client
if rsh is enabled on the server, and you try
rsh server-l username_on_server pwd
it should return your home directory
If rsh works you simply need a script to do it all.
Tell us if rsh works, then I can suggest a sqlplus script too.
2. see 1.
3. this should be in your ~/.cshrc or ~/.profile
4. see 1. or use rsh
5. done automatically by a script
6. see 1.
7. see 1. and mpass' comment
8. see 4.
9. exit
So we end up in 2 suggestions to perform all your tasks:
a. get expect and install on your client, then write a expect script to do all you need
b. try to setup rsh on the server,
you simply need to modify your ~/.rhosts, then you may try rsh from the client
if rsh is enabled on the server, and you try
rsh server-l username_on_server pwd
it should return your home directory
If rsh works you simply need a script to do it all.
Tell us if rsh works, then I can suggest a sqlplus script too.
ASKER
I am not quite following your comment, "see 1" & "see4." Where do you want me to see? Where is expect script?
As I explained earlier, rsh doesn't work. If rsh works, this isn't even an issue...
Thank you for your further help!
As I explained earlier, rsh doesn't work. If rsh works, this isn't even an issue...
Thank you for your further help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The sexiest way is still expect scripts. So here are
the steps.
1- Get expect & tcl/tk source at http://expect.nist.gov
2- Compile & install tcl/tk then expect.
3- Write an expect script to do the above tasks.
This could be subdivided into 2 separate tasks.
Dynix host: Setup a crontab to run the SQL statements etc. It's easier to run from the localhost
and it won't break your expect scripts if the result is
not normal.
Linux host: Write the scripts to get the results then
send you e-mail.
Make sure you see #1. :-) Of course we could all do
that for a huge consulting fee. :-)
the steps.
1- Get expect & tcl/tk source at http://expect.nist.gov
2- Compile & install tcl/tk then expect.
3- Write an expect script to do the above tasks.
This could be subdivided into 2 separate tasks.
Dynix host: Setup a crontab to run the SQL statements etc. It's easier to run from the localhost
and it won't break your expect scripts if the result is
not normal.
Linux host: Write the scripts to get the results then
send you e-mail.
Make sure you see #1. :-) Of course we could all do
that for a huge consulting fee. :-)
dgrimes, thanks for explaining :)
expect is Tcl only (no TK), I also recommend http://www.scriptics.com/ for Tcl(/Tk), it then may point to http://expect.nist.gov too ;-)
expect is Tcl only (no TK), I also recommend http://www.scriptics.com/ for Tcl(/Tk), it then may point to http://expect.nist.gov too ;-)
Did I submit my comment as an answer? I thought I submitted it as a comment. I believe ahoffman is the one who suggested using expect. I only concurred with his answer.
ahoffman, if you want the points please let me know and I will post a question for you to answer. Otherwise I am quite happy to credit for your answers ... and if you have any others you would like me to take credit for ... just let me know :)
dgrimes
ahoffman, if you want the points please let me know and I will post a question for you to answer. Otherwise I am quite happy to credit for your answers ... and if you have any others you would like me to take credit for ... just let me know :)
dgrimes
I go for the answer, not just the points.
Thanks anyway for the gentle offer, dgrimes.
Thanks anyway for the gentle offer, dgrimes.
This worked for me and was very helpful. I spend hours searching the web for such an example. Thanks for your expert advice! I actually needed it to send but was able to modify it to work perfectly. Here is the send version.
#!/bin/csh -f
set u=user
set p=password
while 1
ftp -in sitename <<eof_ftp
us $u $p
send /directory/file.txt file.txt
quit
eof_ftp
exit
#!/bin/csh -f
set u=user
set p=password
while 1
ftp -in sitename <<eof_ftp
us $u $p
send /directory/file.txt file.txt
quit
eof_ftp
exit
#!/bin/csh -f
set u=username
set p=password
while 1
ftp -in systemname << eof_ftp
us $u $p
bin
get filename
quit
eof_ftp
exit
Change the following:
username > your username on that system
password > your password on that system
systemname > the name of the system you are logging into
filename > name of the file you want to ftp
Tell me if you have any problems with this script and I'll help you resolve it. Hope this helps.