SSH shell script does not work


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSH shell script does not work
# 8  
Old 04-20-2010
Quote:
Originally Posted by abdujaparov
How can I pass the passphrase?
ssh is designed to prevent you automatically giving a rawtext password because this is insecure. It has better mechanisms for using the key noninteractively. ssh-agent can hold the key for you to reuse repeatedly once you enter the password just once:
Code:
$ ssh-agent > ~/.ssh-agent
$ . ~/.ssh-agent
$ ssh-add
Enter passphrase for key '/home/gaia_user/.ssh/id_rsa': 
# After this point, you should be able to run ssh noninteractively, ssh-agent will store the key until it's killed.

# 9  
Old 04-20-2010
Hi,
I need to pass to ssh-agent the passphrase at the beginning of the script.
I found something about about this issue and I wrote this:

spawn ssh $USER_SERVER@$HOST_WHITEBOARD
expect "*ssh/id_rsa*"
send -- "${PASSW_SERVER}\r"
send -- "\r"


I have problem with command spawn and send.
If I launch them I receive these errors:

Quote:
[gaia_user@server01 RMS_GSRWorkflow]$ spawn
bash: spawn: command not found
[gaia_user@server01 RMS_GSRWorkflow]$ /usr/local/spawn
bash: /usr/local/spawn: No such file or directory
Quote:
[gaia_user@server01 RMS_GSRWorkflow]$ send
bash: send: command not found
[gaia_user@server01 RMS_GSRWorkflow]$ /usr/bin/send
bash: /usr/bin/send: No such file or directory

If I search these packets with yum I receive these information:

Quote:
[root@server01 RMS_GSRWorkflow]# yum search spawn
Loaded plugins: rhnplugin, security
======================================================================= Matched: spawn =======================================================================
inn.x86_64 : The InterNetNews (INN) system, an Usenet news server.
pexpect.noarch : Pure Python Expect-like module
Quote:
[root@server01 RMS_GSRWorkflow]# yum search send
Loaded plugins: rhnplugin, security
======================================================================= Matched: send ========================================================================
lam.x86_64 : The LAM (Local Area Multicomputer) programming environment.
lam.i386 : The LAM (Local Area Multicomputer) programming environment.
ORBit2.i386 : A high-performance CORBA Object Request Broker
ORBit2.x86_64 : A high-performance CORBA Object Request Broker
arptables_jf.x86_64 : Userspace control program for the arptables network filter.
dbus.i386 : D-BUS message bus
dbus.x86_64 : D-BUS message bus
efax.x86_64 : A program for faxing using a Class 1, 2 or 2.0 fax modem.
exim.x86_64 : The exim mail transfer agent
inews.x86_64 : Sends Usenet articles to a local news server for distribution.
iputils.x86_64 : Network monitoring tools including ping.
mailx.x86_64 : The /bin/mail program for sending e-mail messages.
mgetty.x86_64 : A getty replacement for use with data and fax modems.
mgetty-sendfax.x86_64 : Provides support for sending faxes over a modem.
procps.x86_64 : System and process monitoring utilities.
psmisc.x86_64 : Utilities for managing processes on your system.
pump-devel.i386 : Development tools for sending DHCP and BOOTP requests.
pump-devel.x86_64 : Development tools for sending DHCP and BOOTP requests.
radvd.x86_64 : A Router Advertisement daemon
rsync.x86_64 : A program for synchronizing files over a network.
rsyslog.x86_64 : Enhanced system logging and kernel message trapping daemons
sendmail.x86_64 : A widely used Mail Transport Agent (MTA).
sendmail-cf.x86_64 : The files needed to reconfigure Sendmail.
sendmail-devel.i386 : Extra development include files and development files.
sendmail-devel.x86_64 : Extra development include files and development files.
sendmail-doc.x86_64 : Documentation about the Sendmail Mail Transport Agent program.
sg3_utils.x86_64 : Utils for Linux's SCSI generic driver devices + raw devices
sharutils.x86_64 : The GNU shar utilities for packaging and unpackaging shell archives.
spamassassin.x86_64 : Spam filter for email which can be invoked from mail delivery agents.
synaptics.x86_64 : Synaptics Touchpad Driver
sysklogd.x86_64 : System logging and kernel message trapping daemons.
So I'm blocked at this point.

How can I pass the passphrase only one time at the beginning?
Thanks, bye bye.
# 10  
Old 04-21-2010
Java

I thought Spawn was part of expect and does not require any other external binary.

Anyways..... Could you try this and update the results:

Create two files and chmod 755 them:

File: GetData.sh
Code:
#!/bin/bash
./Query.exp  > /infoman/test/juniper/file.txt

File: Query.exp
Code:
#!/usr/bin/expect -f
spawn $env(SHELL)
send -- "/usr/bin/ssh user@IP"
expect password:
send "Password\r"
send "get system | include mac|Int|Ser|Software"
expect eof

in 2nd file I have put expect -f not -- and also I spawn SHELL not ssh directly ... and most of it is same.

Last edited by chakrapani; 04-21-2010 at 06:17 AM..
# 11  
Old 04-21-2010
Hi,
I tried to execute the script you wrote but I receive this error message:
Quote:
[gaia_user@server01 RMS_GSRWorkflow]$ ./GetData.sh
./GetData.sh: line 2: Query.exp: command not found
What do I forget or what is the mistake I make?
Thanks, bye bye.
# 12  
Old 04-21-2010
Apologies the backtick ` in first script should not be there !! [updated script in my previous post above]

... also try executing 2nd script basically it (2nd script) will throw the output ..

Please make sure expect is correct path ... as mentioned in script
# 13  
Old 04-21-2010
I tried again but I receive error.
I removed the ` and I receive:

Quote:
[gaia_user@server02 ~]$ ./GetData.sh
": no such file or directory
What is this error?
Thanks again, bye bye.
# 14  
Old 04-21-2010
Have you chmod 755 the files

$chmod 755 GetData.sh
and also
$chmod 755 Query.exp

try running ./Query.exp
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Shell script - if statements dont work

hi all, i have made a shell script and it runs until it reaches the if statement, doesn't the ! mean only if the command fails it will echo me that message and then exit can anyone please help me what is wrong with my code? many thanks, rob #!/bin/bash echo "is this archive... (10 Replies)
Discussion started by: robertkwild
10 Replies

2. Shell Programming and Scripting

Ssh remote command doesn't work from script file

I have 10 application servers in a distributed architecture generating their own application logs. Each server has application utility to continuously tail the log. for example following command follows tails and follows new logfiles as they are generated server1$ logutility logtype When I run... (8 Replies)
Discussion started by: indianya
8 Replies

3. Shell Programming and Scripting

Shell script to work on dates

Hi Sir/Madam I have a file data.txt like below file_name date_of_creation x 2/10/2012 y 8/11/2010 z 11/3/2013 a 2/10/2013 b 3/10/2013 c ... (4 Replies)
Discussion started by: kumar85shiv
4 Replies

4. Shell Programming and Scripting

Ssh agent forwarding in script did not work

Sorry for the wrong question. (2 Replies)
Discussion started by: hce
2 Replies

5. Shell Programming and Scripting

ssh does not work in script while running crontab

Hi All, I have prepared a small script to monitor few applications running on diff unix boxes(frontend/backed node1/node2 etc). ssh does not work for node2 when script executed from crontab..:wall: it work fine when i run it manually. Regards, Pavan (4 Replies)
Discussion started by: pavanchouksey
4 Replies

6. UNIX for Dummies Questions & Answers

How to work command 'cd' in shell script?

I have simple script. like that, I am working on /usr/local/src and also under src folder there is a ft folder #!/bin/ksh #!/bin/bash dirpath="/usr/local/src/ft" echo $dirpath cd $dirpath echo displays ok "/usr/local/src/ft" but that doesn't enter "ft" folder. stays in current... (4 Replies)
Discussion started by: F@NTOM
4 Replies

7. AIX

AIX Shell script does not work

Hi. I created schell script for sending messages to some processes in AIX: #!/bin/sh BSE=/infor/ERPLN/bse BSE_TMP=/infor/ERPLN/bse/tmp export BSE BSE_TMP for i in `ps -eo pid,comm | grep bshell | cut -f 1 -d " "` do /something $i done Unfortunatelly this script does not work on... (6 Replies)
Discussion started by: giovanni
6 Replies

8. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

9. Shell Programming and Scripting

$RANDOM does not work inside a shell script

Hi folks I'm coding on Ubuntu 9.04 standard shell. I'm writing a script that needs to generate a random number at some point of its execution. When I do echo $RANDOMas a command inside shell, I clearly get some randomly generated number However when I do i=`$RANDOM` echo $ior even... (14 Replies)
Discussion started by: ksk
14 Replies

10. Shell Programming and Scripting

I need to do a work to my job, but i m new in script shell, someone can help with this..

I need to do a work to my job, but i m new in script shell, someone can help with this.. :confused: Description Bsafe The command creates a backup directory of each month at the command line (arguments of the script). The names of directories to copy will always be specified for the... (4 Replies)
Discussion started by: strshel
4 Replies
Login or Register to Ask a Question