Pass subshell through expect and SSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pass subshell through expect and SSH
# 1  
Old 06-09-2010
Pass subshell through expect and SSH

Hi folks,

What I want to do is to check if there is an instance of running vlc on a remote server, then kill it, and start it again. The code I came up with is:
Code:
#!/bin/bash

expectFcn() {
  expect -c "
  set timeout -1
  spawn ssh \"$1@$2\" \"$4\"
  match_max 100000
  expect {
    -re \".*Are.*yes.*no.*\" {
      send \"yes\r\"
      exp_continue
    }
    \"*?assword:*\" {
      send \"$3\r\"
      send \"\r\"
      interact
    }
  }"
}

...

CMD="if [[ x$`pgrep -x vlc` != x ]]; then /usr/bin/killall -9 vlc; fi; vlc &;"
expectFcn $USER $REMOTE $PASS "$CMD"

but I got stuck at how to pass the subshell `pgrep -x vlc` to the remote through ssh and expect. The subshell is always invoked on the current machine rather than being sent to the remote and invoked there.

Any idea what I am doing wrong?

Thanks,

D.
# 2  
Old 06-09-2010
Hi, wouldn't it be easier to just kill it and start it anyway?

Code:
ssh user@host killall -9 vlc
ssh user@host vlc

Best regards,
Lakris
# 3  
Old 06-09-2010
Quote:
Originally Posted by Lakris
Hi, wouldn't it be easier to just kill it and start it anyway?

Code:
ssh user@host killall -9 vlc
ssh user@host vlc

Best regards,
Lakris
Yeah, I can do that, but I dont like the message "No process vlc found" if there is no instance of vlc is running. The if is to check if there is one running, then it will kill it, otherwise do nothing.

Another thing is that, passing subshell through ssh is fine with double quote, but putting it inside a expect script make it to be invoked on clients.

D.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass path variable on SSH

hi Gurus, Have been struggling with this for a while I have 2 servers , lets say local A and remote B, I need to use both as a part of a pipeline. The folder structure is shared between the two, so I can access the same files and folders from both A and B. When I try to ssh into B from A,... (15 Replies)
Discussion started by: senhia83
15 Replies

2. Solaris

SSH keyless pass on Solaris 11

Need assistance in troubleshooting SSH keyless. Below are the steps i have done . Appreciate more inputs Node1 and Node2 Node1 ssh-keygen -t rsa -b 2048 Copy .ssh/id_rsa.pub to Node2 with cat id_rsa.pub | ssh id@node2 'cat >>.ssh/authorized_keys' Node2 touch authorized_keys... (9 Replies)
Discussion started by: ajayram_arya
9 Replies

3. Shell Programming and Scripting

Ssh = ssh expect and keep everything not change include parameter postion

I have write a script which contains ssh -p 12345 dcplatform@10.125.42.50 ssh 127.0.0.1 -p 5555 "$CMD" ssh root@$GUEST_IP "$CMD" before I use public key, it works well, now I want to change to "expect", BUT I don't want to change above code and "parameter position" I can post a... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

4. Shell Programming and Scripting

How to pass variable with spaces from shell to expect?

I need call expect script from shell script and pass values some of which could contain space. How to make expect to treat such values as one variable? (1 Reply)
Discussion started by: urello
1 Replies

5. UNIX for Dummies Questions & Answers

How to pass variables in Expect command?

Hi All, I need to frame a unix script to logon to a unix box. The credentials needs to be obtained from a property file on the same location. I am trying to use 'expect' and 'spawn' command to meet this req. When I am passing values, these commands are working fine. but when I am trying to... (3 Replies)
Discussion started by: mailkarthik
3 Replies

6. Shell Programming and Scripting

ssh via expect

(Crossposting note: I have already posted this article on comp.lang.tcl 6 days ago and on the tek-tips dot com forum 3 days ago. This is posted here again, because I didn't get any response on my original articles there). I use the following script on Solaris to log into a remote host: ... (3 Replies)
Discussion started by: rovf
3 Replies

7. Shell Programming and Scripting

Sending test pass to a folder in expect

still new to this expect useing bach shell to cammand expect script i tink i have that right! i want to have the test im running upon every complted cycle copyed to a folder. cant seem to get it to work. Ive tryed log_file -a $globallogdir/deveoper.log proc dbglog {notsure what... (0 Replies)
Discussion started by: melvin
0 Replies

8. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

9. Shell Programming and Scripting

SSH Expect Script

Ok, i don't know if anyone else here have had to deal with something like this before, but here's my situation. I have about 1000+ servers I need to log into to do something. What i need to do is to log into each server, go to a certain directory on each of the servers, copy the files that... (3 Replies)
Discussion started by: SkySmart
3 Replies

10. UNIX for Advanced & Expert Users

expect and ssh

hello I installed expect on my solaris box. now I want to execute this command on several servers as root (all of them have the same root password): for i in 1 2 3; do ssh root@"srv"$i" ls /; done; I want of course to skip these 2 steps: The authenticity of host 'srv3 (172.21.26.25)'... (4 Replies)
Discussion started by: melanie_pfefer
4 Replies
Login or Register to Ask a Question