Not able to come out from remote server using here document


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to come out from remote server using here document
# 1  
Old 01-31-2009
Not able to come out from remote server using here document

Please help me out with one highlighted in RED

#!/bin/bash
STAGING_HOSTS="san man hand"
for HOST in $STAGING_HOSTS
do

ssh $HOST <<EOT
echo "CVServer is being stopped on $HOST "
pkill CVServer
sleep 20

echo "!!! Checking if CVServer is DOWN on $HOST !!!"
ps -ef | grep CVServer | grep -v grep
CHECK_PROCESS=$?

if [ $CHECK_PROCESS = 0 ]; then
PROCESS_ID=`ps -ef|grep CVServer|grep -v grep |awk '{print $2}'`
echo "CVServer is still running with $PROCESS_ID , Hence killing it..."
kill -9 $PROCESS_ID
sleep 5

ps -ef | grep CVServer | grep -v grep
# elif [ $? = 0 ]; then
# echo "Process is still running... Hence killing it"
# kill -9 $PROCESS_ID
else
echo "!!! CVServer is DOWN on $HOST !!!"
fi

echo "Bringing UP the CVServer on $HOST "
/abc/def/ghi/CvServer/default/sbin/Start_CVServer
sleep 10
ps -ef | grep CVServer | grep -v grep
if [ $? = 0 ];
then
PROCESS_ID_UP=`ps -ef|grep CVServer|grep -v grep |awk '{print $2}'`
echo "CVServer is UP on $HOST with $PROCESS_ID_UP id $PROCESS_ID_UP "

##Here the code gets stuck...not able to come out and login to other server mentioned in STAGING_HOSTS variable
else
echo "CVServer is not UP on $HOST with $PROCESS_ID_UP id "
fi
EOT
done
}

mv -f $LOG $LOG.old
stuff $* 2>&1 | tee $LOG



SCREEN OUTPUT
---------------
Pseudo-terminal will not be allocated because stdin is not a terminal.
CVServer is being stopped on man
!!! Checking if CVServer is already DOWN on man !!!
-bash: line 9: [: =: unary operator expected
!!! CVServer is DOWN on man !!!
Bringing UP the CVServer on man
gtp 26508 1 0 07:50:01 ? 0:00 /abc/def/ghi/CvServer/default/bin/CVServer
CVServer is UP on wedges1 with id 26508

^Csan:/tmp>
# 2  
Old 01-31-2009
Your output and the script don't match.

Also, calling a remote script using <<< is a little odd. Also realize, that expressions like:
Code:
CHECK_PROCESS=$?
if [ $CHECK_PROCESS = 0 ]; then

gets interpolated first on the localhost. So the command that is actually processed on the remote server might be:
Code:
CHECK_PROCESS=
if [ = 0 ]; then

The first command after <<< EOT should be set -x.
# 3  
Old 02-14-2009
otheus,

I used the set -x option. but still the problem is not resolved.
I am still not able to come out of the loop . the code gets stucks there itself.

Pls help,.
# 4  
Old 02-14-2009
the set -x option is for debugging. You should see some debugging output from the shell. It will be in the log file you created. Post that please.
# 5  
Old 02-14-2009
Here is the log

wedges1:/tmp> ./test
mv: cannot access /ilx/ops/log/test.log
tee: /ilx/ops/log/test.log: No such file or directory
Pseudo-terminal will not be allocated because stdin is not a terminal.
+ echo 'CVServer is being stopped on drivers1 '
CVServer is being stopped on drivers1
+ pkill CVServer
+ sleep 10
+ echo '!!! Checking if CVServer is DOWN on drivers1 !!!'
!!! Checking if CVServer is DOWN on drivers1 !!!
!!! CVServer is DOWN on drivers1 !!!
Bringing UP the CVServer on drivers1
+ ps -ef
+ grep CVServer
+ grep -v grep
+ CHECK_PROCESS=
+ '[' = 0 ']'
-bash: line 10: [: =: unary operator expected
+ echo '!!! CVServer is DOWN on drivers1 !!!'
+ echo 'Bringing UP the CVServer on drivers1 '
+ . /ilx/gtp/pkg/CVServer/CURRENT/sbin/Start_CVServer
++ GTP_ROOT=/ilx/gtp
++ CVSERVER_PATH=/ilx/gtp/pkg/CVServer
++ CVSERVER_BINARY=CVServer
++ PID_FILE=/ilx/gtp/pkg/CVServer/data/.CVServer.Pid
++ LOCK_FILE=/ilx/gtp/pkg/CVServer/data/.CVServer.Lock
+++ which rm
++ RM=/usr/bin/rm
+++ which kill
++ KILL=/usr/bin/kill
++ GTP_CONTROL_LIB_ROOT=/ilx/gtp/pkg/GTPcontrol
++ export GTP_CONTROL_LIB_ROOT
++ LD_LIBRARY_PATH=/ilx/gtp/lib:
++ export LD_LIBRARY_PATH
++ '[' -f /ilx/gtp/pkg/CVServer/data/.CVServer.Lock ']'
+++ which sleep
++ SLEEP=/usr/bin/sleep
++ /usr/bin/sleep 4
++ /usr/bin/sleep 2
++ /ilx/gtp/pkg/CVServer/CURRENT/bin/CVServer
+ sleep 5
+ ps -ef
gtp 17464 16775 0 09:38:30 ? 0:03 /ilx/gtp/pkg/CVServer/CURRENT/bin/CVServer
CVServer is UP on drivers1 with id
+ grep CVServer
+ grep -v grep
+ '[' 0 = 0 ']'
+ PROCESS_ID_UP=14624
+ echo 'CVServer is UP on drivers1 with id '
^Cwedges1:/tmp>

# 6  
Old 02-14-2009
replace
Code:
ps -ef | grep CVServer | grep -v grep
CHECK_PROCESS=$?
if [ $CHECK_PROCESS = 0 ]; then

with
Code:
if ps -ef | grep CVServer | grep -v grep; then

# 7  
Old 02-14-2009
Thanks, but

Bit the code stuck at the below... and not able to comeout of remote shell.

. /ilx/gtp/pkg/CVServer/CURRENT/sbin/Start_CVServer
sleep 5
ps -ef | grep CVServer | grep -v grep
if [ $? = 0 ];
then
PROCESS_ID_UP=`ps -ef|grep CVServer|grep -v grep |awk '{print $2}'`
echo "CVServer is UP on $HOST with id $PROCESS_ID_UP "
else
echo "CVServer is not UP on $HOST with $PROCESS_ID_UP id "
fi
EOT
done
}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

2. Shell Programming and Scripting

Sudo connect to a remote server and execute scripts in remote server

Hello Every one!! I am trying to write a shell script which will connect to a remote server and execute scripts which are at a certain path in the remote server. Before this I am using a sudo command to change the user. The place where I am stuck is, I am able to connect to the... (6 Replies)
Discussion started by: masubram
6 Replies

3. Shell Programming and Scripting

Do I require remote login access to a windows server to transfer files from a UNIX server

Hi All I need to transfer a file from a UNIX server to a windows server. I saw that it is possible to do this using scp command by looking at the forum listed below: ... (2 Replies)
Discussion started by: vx04
2 Replies

4. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

5. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

6. UNIX for Advanced & Expert Users

Strange Issue with document upload through Web server

Hi , I am hosting a website where in users log into their account and upload documents. The website is hosted on a Apache web server(4 nodes) sitting on RHEL VM's and load balanced by radware. The issue i am facing is that the documents that are uploaded through the web site sometimes show... (2 Replies)
Discussion started by: Hari_Ganesh
2 Replies

7. Programming

SFTP from one remote server to another remote server from desktop

Hi, I have 1. lappy 2. server A 3. server B Now, what i need is to run a command from lappy that will sftp a file from server A to server B. Please guide me to achieve this. -akash (1 Reply)
Discussion started by: akash.mahakode
1 Replies

8. Shell Programming and Scripting

preserving the timestamp of a file when copied from remote server to local server using ftp

Hi, I need to copy few files from remote server to local server. I write a shell script to connect to the remote server using ftp and go to that path. Now i need to copy those files in the remote directory to my local server with the timestamp of all those files shouldnt be changed. ... (5 Replies)
Discussion started by: arunkumarmc
5 Replies

9. HP-UX

Transfer file from local unix server to remote server

want to remove the thread thanks (2 Replies)
Discussion started by: indira
2 Replies

10. Shell Programming and Scripting

FTP multiple files from remote server to local server

Hi, I am facing a weired problem in my FTP script. I want to transfer multiple files from remote server to local server everyday, using mget * in my script. I also, want to send an email for successful or failed FTP. My script works for file transfer, but it don't send any mail. There is... (2 Replies)
Discussion started by: berlin_germany
2 Replies
Login or Register to Ask a Question