Sponsored Content
Top Forums UNIX for Advanced & Expert Users Launching a process in remote machine Post 302468408 by purdym on Tuesday 2nd of November 2010 04:05:45 PM
Old 11-02-2010
I run this on HP-UX to SSH to an AIX server.

/homeroot/.rsshpw - contains an encrypted password.
/home/unxsa/sbin/decrypt - is a perl program to decrypt the password.

You will have to put root's ssh passphrase into a file.

Code:
#!/usr/bin/expect -f
#
# Name: ssh_to_node_noninteractively.HP-UX
#
# Purpose: to run a command on a remote machine
#
# Date: June 2010
#
# Version: 1.2
#
# Required Parameters:
# -------------------------------------------------------------------------
#
# Optional Parameters:
# -------------------------------------------------------------------------
#
# Example execution statments:
# -------------------------------------------------------------------------
#
# Variables:
# -------------------------------------------------------------------------
#
# Change History:
# -------------------------------------------------------------------------
# Date          Name            Comments
# _________________________________________________________________________
# June 2010     purdym          new


###################################################################################
# Variables
###################################################################################
set timeout 3
match_max 100000

##################################################################################
# print_options
##################################################################################
if {$argc!=2} {
   send_user "usage: $argv0 hostname command\n"
   exit
}

# script must be run by root user
set whoami [exec id -u]
if {$whoami!=0} {
   send_user "You must be a root user to run this script\n"
   exit
}
###################################################################################
# command line args
###################################################################################
set host [lindex $argv 0]
set command [lindex $argv 1]

###################################################################################
# Start
###################################################################################
# use exec, not spawn here
set password [exec /home/unxsa/sbin/decrypt [exec /usr/bin/cat /homeroot/.rsshpw]]

# opem shell
spawn /usr/bin/ksh

# send passwd command
send -- "ssh -q '$host' '$command'\r"
expect {
   "'/homeroot/.ssh/identity':*" { send "$password\r" }

}

#
expect {
   eof
   timeout close

}

close

###################################################################################
# exit
###################################################################################
exit


Example:

Code:
:/homeroot>uname -a
HP-UX <hidden> B.11.31 U ia64 0489838128 unlimited-user license

:/homeroot>ssh_to_node_noninteractively.HP-UX <hidden> /usr/bin/uname
spawn /usr/bin/ksh
ssh -q '<hidden>' '/usr/bin/uname'
root@wpgux001:/homeroot>ssh -q '<hidden>' '/usr/bin/uname'
Enter passphrase for key '/homeroot/.ssh/identity':
AIX
:/homeroot>



Last edited by purdym; 11-02-2010 at 05:37 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

leave a process running in a remote machine

Hi, I would like to run a process in my gentoo machine from a consolte (putty) in Windows and would like that this process keep on going when I close the console in Windows (i.e closing this session). The process should take a long time and I do not want to leave the Windows machine running... (3 Replies)
Discussion started by: pbasil
3 Replies

2. UNIX for Dummies Questions & Answers

Tar to remote machine

Is there a way to use Tar (not GNU) to automaticallly create a tar file on a remote machine. the source files will be local, but I would like tthe tar file to be remote. Thanks. (2 Replies)
Discussion started by: hshapiro
2 Replies

3. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

4. Red Hat

Problem launching process as BG with &

After i launch the process as back ground, when I try to grab the shell by sending the enter, process is going to Stopped state. How do I successfully run the job in bg with &. Thanks in Advance (1 Reply)
Discussion started by: hansini
1 Replies

5. Linux

Launching X apps from a machine without X installed

Hi. Here's my setup: a workstation with an X server a CentOS server with no X server installed (development, security is not a concern) a GUI application installed on the server When I ssh to that machine, I get: ssh -Xl root 192.168.x.x Warning: untrusted X11 forwarding setup... (4 Replies)
Discussion started by: flj
4 Replies

6. UNIX for Advanced & Expert Users

Needs help in launching a console application with the help of daemon process

Hi All, I am facing problem in launching a application with the help of a daemon process. Actually the application is based on command line that reads various commands for controlling the application from the console and accordingly executes those commands. The application always interact with... (3 Replies)
Discussion started by: gopallinux
3 Replies

7. UNIX for Dummies Questions & Answers

How a process can check if a particular process is running on different machine?

I have process1 running on one machine and generating some log file. Now another process which can be launched on any machine wants to know if process1 is running or not and also in case it is running it wants to stream the logs file generated by process1 on terminal from which process2 is... (2 Replies)
Discussion started by: saurabhnsit2001
2 Replies

8. UNIX for Advanced & Expert Users

FTP While transfering files to local machine to remote machine

Hi Am using unix Ksh Am getting the problem while transferring zero size files through the script . When i transfer zero size files from local machine to remote machine manually i can able to do it . My question its beause of zero size files am not able to transfer through script ? or its... (2 Replies)
Discussion started by: Venkatesh1
2 Replies

9. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to 192.168.1.15 Server from my machine, my ip was 192.168.1.99 Source Destination was UP, with IP 192.168.1.15. This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

10. Shell Programming and Scripting

Help with fetching the data from remote machine from my jumpbox(local machine)

Team, Presently i am running a script from my local box(i.e jumpbox) to all the remote machines.Basically fetching basic queries like pwd,mkdir,touch etc and i am able to successfully fetch it from my local machine.But when i want to check certain database related queries like the dbstat... (20 Replies)
Discussion started by: whizkidash
20 Replies
NETRC(5)						      BSD File Formats Manual							  NETRC(5)

NAME
netrc -- user configuration for ftp SYNOPSIS
~/.netrc DESCRIPTION
This file contains configuration and autologin information for the File Transfer Protocol client ftp(1). The .netrc file contains login and initialization information used by the auto-login process. It resides in the user's home directory. The following tokens are recognized; they may be separated by spaces, tabs, or new-lines: machine name Identify a remote machine name. The auto-login process searches the .netrc file for a machine token that matches the remote machine specified on the ftp command line or as an open command argument. Once a match is made, the subsequent .netrc tokens are processed, stopping when the end of file is reached or another machine or a default token is encountered. default This is the same as machine name except that default matches any name. There can be only one default token, and it must be after all machine tokens. This is normally used as: default login anonymous password user@site thereby giving the user automatic anonymous ftp login to machines not specified in .netrc. This can be overridden by using the -n flag to disable auto-login. login name Identify a user on the remote machine. If this token is present, the auto-login process will initiate a login using the specified name. password string Supply a password. If this token is present, the auto-login process will supply the specified string if the remote server requires a password as part of the login process. Note that if this token is present in the .netrc file for any user other than anonymous, ftp will abort the auto-login process if the .netrc is readable by anyone besides the user. account string Supply an additional account password. If this token is present, the auto-login process will supply the specified string if the remote server requires an additional account password, or the auto-login process will initiate an ACCT command if it does not. macdef name Define a macro. This token functions like the ftp macdef command functions. A macro is defined with the specified name; its con- tents begin with the next .netrc line and continue until a null line (consecutive new-line characters) is encountered. If a macro named init is defined, it is automatically executed as the last step in the auto-login process. SEE ALSO
ftp(1), ftpd(8) Linux NetKit (0.17) September 23, 1997 Linux NetKit (0.17)
All times are GMT -4. The time now is 09:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy