Ssh bash script exits without remote command completion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ssh bash script exits without remote command completion
# 1  
Old 06-30-2016
Ssh bash script exits without remote command completion

Hi,

My goal is to connect from unix server A to windows server B and call a bat file on windows.
I am able to succeed in remoting to windows and executing a command, the issue i am facing is the shell scrip is exiting without making sure of bat file success.
Can you please help me in modifying the below script or suggest something better to execute command on remote machine and wait for its success/failure.

Code:
#!/usr/bin/bash

HOST="localhost"
USER="username"
PASS="pass"
CMD=$@


VAR=$(expect -c "
spawn ssh -o PreferredAuthentications=password -o StrictHostKeyChecking=no $USER@$HOST $CMD
match_max 100000
expect \"*?assword:*\"
send -- \"$PASS\r\"
expect "\\$"
expect -re "$USER.*"
send "logout"
")

sample .bat file i am using for test is

Code:
@echo off


ping 127.0.0.1 

if "%errorlevel%"=="0" cls &Echo %errorlevel%
if "%errorlevel%"=="1" cls &Echo %errorlevel%

timeout /t 60

Thanks a lot in advance

Last edited by vgersh99; 06-30-2016 at 06:05 PM.. Reason: code tags, please!
# 2  
Old 06-30-2016
What is your used SSH-Server-Software on Windows?
# 3  
Old 06-30-2016
Open ssh
# 4  
Old 06-30-2016
Can you show the output of the script so far?

... and please remove that for the time testing:

Code:
 @echo off

What's your Windows OS version?
# 5  
Old 06-30-2016
Windows server 2012
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script to compare file all the files exits or not

Currently i am building a script like based on region parameter it will filter the records in config file and then it will create a text file like ab.txt and it will read the path location in that file and now i need to compare the files name in the config file to files in the path of the config... (1 Reply)
Discussion started by: saranath
1 Replies

2. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

3. Shell Programming and Scripting

Execute a command after ssh exits

In my .tcshrc I define and run an alias to set my terminal title. The title contains the hostname. I do this because I ssh to other machines a lot and I always need to know which host I am typing in. The alias is defined and run in the .tcshrc like this... alias tt 'echo -n "^0;`hostname -s`^G"'... (5 Replies)
Discussion started by: salvadorjoshua
5 Replies

4. UNIX for Dummies Questions & Answers

Bash-completion on shell script

Hello I want use bash_completion on a script but the information on the internet give me not a solution. The scrip start with "cd" to a direction Than the script do "ls" Than I must give a name of a sub-direction and here I want to use <TAB>, so when I have a direction with the name smith... (2 Replies)
Discussion started by: thailand
2 Replies

5. 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

6. Shell Programming and Scripting

bash script to execute a command remote servers using ssh

Hello, I am running into few issues, please suggest me what I am missing. I am running this script on a linux host. Main idea of this script is to, login to each host via ssh and get uid of user, service user that I trying to run this script, has already deployed ssh keys and provide sudo... (8 Replies)
Discussion started by: bobby320
8 Replies

7. Shell Programming and Scripting

'script' command exits immediately

I'm trying to capture the output of some commands with the 'script' utility. Normally, I would type 'script /path/to/output/file', then enter commands, then hit ctrl+D to end the 'script' capture. I'm having trouble with it on a server. Upon starting 'script', it exits immediately before I type... (6 Replies)
Discussion started by: jalburger
6 Replies

8. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

9. HP-UX

Succesfully completion of a command in unix script

Hi, I want to wrote a script. say it has 4 command(e.g. a,b,c,d). I want my script to progress b if a completes succesfully. So can you please let me know what command/parameter i need to set. Thanks, Malay (2 Replies)
Discussion started by: malaya_17
2 Replies

10. Shell Programming and Scripting

Script exits with $? not 0 randomly, how can I see what command failed?

Hi! I have this situation with 3 shellscripts. One is a "startscript" that simply calls other scripts. This one is scheduled with cron to run at regular intervals. That script runs what I'll refer to as Script 1. Script 1 in turn runs script 2 (import_catalogs_buyer.sh) Sometimes, seemingly... (2 Replies)
Discussion started by: trailsmoke
2 Replies
Login or Register to Ask a Question