Solved

Automation of telnet

Posted on 2007-03-26
8
428 Views
Last Modified: 2013-12-26
Hi,
I've a situation where I'm using KSH (AIX) and need to write a shell script.
From one server(say ServA), I need to check continously for some processes and if some of them are down, then need to bring up the processes from another server (say ServB), need to connect to ServB from ServA thru either telnet or ssh
How do I approach this, first telnet should be done automatically when the trigger occurs & then run another shell script in ServB which will start the processes.

Thanks & Regards
prasen
0
Comment
Question by:prasen120998
  • 3
  • 2
8 Comments
 

Accepted Solution

by:
mwdonovan earned 63 total points
ID: 18805755
Least complicated and most robust method is to have two watchers, one on each machine, and a shared directory on ServB that can be seen from ServA via whatever cross-mount method your admins prefer.

Have the watcher script on ServB run every few minutes or seconds, depending on desired response speed... whatever you do, don't have the watcher cycle continuously. When the ServB watcher finds a desired running process, it touches a file in the shared directory that is named appropriately; such as, critical_process_a_heartbeat.tmp

The watcher on ServA runs and sleeps on a similar schedule. It looks for the presence of the heartbeat file and checks its time-stamp against current time.

If the heartbeat file is not present or the time-stamp is older than a given limit, then the process is assumed to not be running. The ServA watcher removes the shared heartbeat file (if present), and creates a restart file in the shared directory.

The ServB watcher not only looks for running processes, but restart files as well. If it finds critical_process_a_restart, it will do whatever is required to restart the dead process. Make sure a process is not running before attempting a restart, just in case someone beat you to it...

Notice that you haven't messed with telnet or ssh remote calls at all, beyond having your admins set up the shared directory.

Hope this helps :)

mwdonovan

0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 62 total points
ID: 18878210
# for example on ServA:
ssh user@ServB other-shell-script

(assuming that you have setup ssh with keys for user)
0
 
LVL 4

Expert Comment

by:rwaldicott
ID: 19034192
you can do this using some .NET or Java classes

See the TelnetSession and SshSession classes here:

http://www.jscape.com/sshfactory/  (Java)

http://www.jscape.com/sshfactorydotnet/ (.NET)

http://www.jscape.com/telnetfactorydotnet/ (.NET)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Expert Comment

by:mwdonovan
ID: 19034854
Only if you want it to be overly complex, terribly slow, and indecipherable. Simple shell scripts can do the job faster and cleaner with no dependency on .NET or the complexity of Java. Using either in this situation is a bit like using a nuclear weapon to swat a fly.

Cheers :)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 19038573
if nuclear things are java/.net driven, there's enough time to escape ...
SCNR ;-)
KISS -keep it simple stupid
0
 

Expert Comment

by:mwdonovan
ID: 19040916
Hah - good point... hopefully, the DoD won't use .net or java for deployed tactical systems ;)

Prasen - have you made progress or do you need some skeleton scripts/examples?
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
importing users to Security group 2 50
Access Control Entries lost in Windows folders 3 53
IE 11 + long running scripts 3 52
Powershell  and PSExec = Password failure 5 21
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question