Pause for remote computing in Telnet script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pause for remote computing in Telnet script
# 1  
Old 06-18-2010
Pause for remote computing in Telnet script

I am running a telnet script that connects to a database server and executes sql scripts. While the remote database is processing the commands within the sql scripts, my telnet script continues to send commands. Okay, that's fine. They get queued up in the remote server and executed sequentially. However, once the telnet script sends the last command, the script ends and the session closes. All of the commands that were queued up while the remote server was busy processing, never get run.

Here is the outline of my code:
Code:
TelnetDbServer()
{
(echo "servername"
sleep 20
echo "username"
sleep 5
echo "password"
sleep 5
echo "cd /dbscriptPath"
sleep 2
echo "..execute script1.sql" #pseudo
sleep 2 
echo "..execute script2.sql" #pseudo
....
sleep 2
echo "..execute scriptN.sql" #pseudo
sleep 2
echo "exit") | telnet
}


Sample Output

[remoteHost]$ ..execute script1.sql
script1.sql commands running running running
..execute script2.sql
..execute script3.sql
..execute script4.sql
..execute script5.sql
..execute script6.sql
exit
Connection closed by foreign host.
[localHost]#

This shows one command is being run while the others are being pushed into the stack, but the telnet script exits before they get run.

What doesn't work:
I cannot use expect because this script is to be used on many machines which do not have expect installed, I don't want to bother with installing expect on all of them.
I tried using read myVar, read -p myVar, echo "read myVar", echo "read -p myVar". These work on korn but don't work on bash in this situation. It just skips right through to exit.
I would prefer not to set a ridiculously high sleep value as a solution. The point of this script is to save time, not waste it in sleep.

Ideal Solution
Ideally I would like my telnet script to wait until the remote server has finished executing the sql scripts, then exit without user input.
# 2  
Old 06-18-2010
SSH

You might want to look at SSH as a far more secure alternative to Telnet.

Brad
Crackednoodle
# 3  
Old 06-19-2010
Add all the commands into a single script and run as:
Code:
nohup bigscript &
exit

# 4  
Old 06-21-2010
Thanks jgt, that works perfectly.

New format is:
Code:
TelnetDbServer()
{
(echo "servername"
sleep 20
echo "username"
sleep 5
echo "password"
sleep 5
echo "cd /dbscriptPath"
sleep 2
echo "echo "execute script1.sql" >>dbScript.sh" #pseudo
sleep 2 
echo "echo "..execute script2.sql" >>dbScript.sh" #pseudo
....
sleep 2
echo "echo "..execute scriptN.sql" >>dbScript.sh" #pseudo
sleep 2
echo "chmod 777 dbScript.sh"
sleep 2
echo "nohup ./dbScript.sh &"
sleep 2
echo "exit"
sleep 2
echo "exit") | telnet
}

I then sleep 30, ftp to the server, get the nohup.out file, grep for a complete staus in this file, and echo the results.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

Ping remote sever, nc, telnet, whatever

I put this thread to shell and bsd, because I want to resolve this matter on bsd. May somebody can explain to me how to ping a remote server, in unix. BTW the following code examples were tried on a linux system as well, with the same output, nothing. But on my bsd are not installed nmap neither... (4 Replies)
Discussion started by: 1in10
4 Replies

2. Shell Programming and Scripting

Pause processes in remote host and resume execution in another remote host

Hi, Given addresses of 2 remote machines, using a shell script is it possible to get the state of running processes in "src" stop all the processes in "src" exit out of "src" ssh into "dest" resume the state of executing processes captured in step 1 in "dest" Assumption: "src" is... (3 Replies)
Discussion started by: Saeya Darsan
3 Replies

3. Shell Programming and Scripting

Creating a script requiring a pause for user input

Hi I'm trying to create a basic script that pauses for user input to verify a file name before generating the output. I have numerous SSL certificate files which I am trying to determine the expiry date so what I'm trying to do is write a script so that is pauses to request the name of the .pem... (9 Replies)
Discussion started by: Buddyluv
9 Replies

4. Shell Programming and Scripting

How to have my ksh script pause, until something appears in the logs.?

All, Is there some way to have my KSH script pause, until the word "DONE!" appears in the logfile /logs/log.txt? Difficulty: The word "DONE!" may already be present in logs from the past. So I anticipate tail -0f may (somehow?) need to be done in the background, instead of grepping in a... (16 Replies)
Discussion started by: chatguy
16 Replies

5. Solaris

Logging remote telnet sessions via script

Hi, My requirement - for security purpose - I want all root logins to my solaris servers are done by a script kept in a separate unix box. This script will telnet into remote solaris server with root user and log every session via log file. Now my purpose is to log every telnet session... (3 Replies)
Discussion started by: rahul_jain250
3 Replies

6. Shell Programming and Scripting

How to pause a shell script

Hi, I've written a shell script to take photos with my camera. After every picture taken, the picture is transmitted to the computer via usb and then deleted on the camera. But sometimes there's an error and the picture is not deleted and so, after a certain time, the camera chip will be... (4 Replies)
Discussion started by: McLennon
4 Replies

7. Shell Programming and Scripting

Script Pause Until Rsync Is Done Transferring

Alright, I have this script that pulls files from a few locations, process those files, creates a zip file, rsync's it and then removes everything. The problem that I'm having is that I do not know how large the rsync'ed zip file is going to be. Right now I'm using a sleep command before I... (4 Replies)
Discussion started by: droppedonjapan
4 Replies

8. Shell Programming and Scripting

problem with remote execution of script using telnet

Hi all, i am trying to remotely execute a script from a different server. this is the code that i use : #!bin/sh pwd (sleep 1 echo "username" sleep 2 echo "pwd" sleep 2 echo "cd /path/to/file" if then echo "script1.sh" echo "mailx -s "Task Executed"... (1 Reply)
Discussion started by: sais
1 Replies

9. UNIX for Dummies Questions & Answers

telnet to remote server

Hi every1 well i am new to unix scripting but i have been seeking help from this forum the question i want to write a script to telnet to a remote server and put the username and pwd in the script the problem is that i want to run some commands on the remote server and get the results in a... (2 Replies)
Discussion started by: hassanabbas
2 Replies

10. UNIX for Dummies Questions & Answers

telnet in for remote admin but not getting it

I have been using rsh, and vnc to access my computer from outside my network. I can do all the simple browsing's but when i go to start or stop apache httpd, or some other deamon commands I am running into problems. I log in as a standered user and the use % su to switch over to root. However,... (4 Replies)
Discussion started by: macdonto
4 Replies
Login or Register to Ask a Question