LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-16-2010, 04:17 AM   #1
buee
Member
 
Registered: May 2009
Posts: 81

Rep: Reputation: 16
Command over SSH won't go in to background


Ok, so this one baffles me. I'm trying to get a script to do internal speed tests on demand. I'm using iperf. The bash commands are below.

Code:
#!/bin/bash

set -ax

desktoppath="/home/buee/Desktop"
iperfserver=192.168.111.230
killfile="/home/buee/Desktop/Kill.txt"

echo 
echo "Please input the customer's name..."
read customer
clear

ssh buee@$iperfserver < $killfile
ssh buee@$iperfserver "iperf -s"
sleep 2
xterm -e "iperf -c $iperfserver -t 20 -i 2 -r -d > $desktoppath/$customer"
sleep 2
kill `ps aux | grep iperf | awk '{print $2}' | head -1`
ssh buee@$iperfserver < $killfile

ssh buee@$iperfserver "iperf -s -u" &
sleep 2
xterm -e "iperf -c -u $iperfserver -t 20 -i 2 -r -d >> $desktoppath/$customer"
sleep 2
kill `ps aux | grep iperf | awk '{print $2}' | head -1`
ssh buee@$iperfserver < $killfile

exit 0
The first portion:

Code:
ssh buee@$iperfserver < $killfile
ssh buee@$iperfserver "iperf -s"
sleep 2
xterm -e "iperf -c $iperfserver -t 20 -i 2 -r -d > $desktoppath/$customer"
sleep 2
kill `ps aux | grep iperf | awk '{print $2}' | head -1`
ssh buee@$iperfserver < $killfile
works beautifully, no issues at all.

But the second part:

Code:
ssh buee@$iperfserver "iperf -s -u" &
sleep 2
xterm -e "iperf -c -u $iperfserver -t 20 -i 2 -r -d >> $desktoppath/$customer"
sleep 2
kill `ps aux | grep iperf | awk '{print $2}' | head -1`
ssh buee@$iperfserver < $killfile
Gives me this:

Code:
+ ssh buee@192.168.111.230 'iperf -s -u'
+ ssh buee@192.168.111.230 'bg 1'
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size:   112 KByte (default)
------------------------------------------------------------
bash: line 0: bg: no job control
+ sleep 2
+ xterm -e 'iperf -c -u 192.168.111.230 -t 20 -i 2 -r -d >> /home/buee/Desktop/Test'
+ sleep 2
++ ps aux
++ grep iperf
++ awk '{print $2}'
++ head -1
+ kill 3420
The only difference between the iperf command in portion A and portion B is B has a -u switch in there that will test with UDP protocol. I figured since I got some output, I'd try sending the command to the back. This process will not go to the background. I tried tacking a '&' to the end of it, I tried following it up with a 'bg 1' through SSH immediately after, I tried "iperf -s -u && bg" as well as "... && bg 1", I tried opening it in a different terminal window on the remote machine, I tried opening it on a different bash shell on the remote machine, nothing seems to help. The following command issued on the local machine completes in less than a second, but it doesn't make sense because it's not picking up a server on the other side of the connection, it should at least have a few seconds to timeout, not just proceed. Any ideas?
 
Old 10-16-2010, 05:22 AM   #2
ScottSmith
LQ Newbie
 
Registered: Mar 2004
Distribution: Debian - Sid
Posts: 23

Rep: Reputation: 1
Quote:
ssh buee@$iperfserver "iperf -s -u" &
I am no scripting expert but wouldn't the & go inside the quotes

Quote:
ssh buee@$iperfserver "iperf -s -u &"
It's just a thought

Scott Smith
 
Old 10-16-2010, 07:41 AM   #3
buee
Member
 
Registered: May 2009
Posts: 81

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ScottSmith View Post
I am no scripting expert but wouldn't the & go inside the quotes



It's just a thought

Scott Smith
I've tried it both ways. I think that if it's inside the quotes, it gets passed along with the command via SSH and doesn't do me any good. I would need the SSH command itself to go to the background to allow the script to continue.
 
Old 10-16-2010, 08:45 AM   #4
buee
Member
 
Registered: May 2009
Posts: 81

Original Poster
Rep: Reputation: 16
I got it working

Here's the script:

Code:
#!/bin/bash

set -ax

desktoppath="/home/buee/Desktop"
iperfserver=192.168.111.230
myip=192.168.111.152
killfile="/home/buee/Desktop/Kill.txt"

echo 
echo "Please input the customer's name..."
read customer
clear

ssh buee@$iperfserver < $killfile
ssh buee@$iperfserver "iperf -s" &
sleep 15
xterm -e "iperf -c $iperfserver -t 20 -i 2 -r > $desktoppath/$customer"
sleep 30
cat $killfile
ssh buee@$iperfserver < $killfile

ssh buee@$iperfserver < $killfile
ssh buee@$iperfserver "iperf -u -s -D" &
sleep 15
iperf -c $iperfserver -t 20 -i 2 -r -u >> $desktoppath/$customer &
sleep 60
kill -9 `ps aux | grep iperf | awk '{print $2}' | head -1`
ssh buee@$iperfserver < $killfile

cat $killfile
xterm -e "iperf -s" &
sleep 10
ssh buee@$iperfserver "iperf -c $myip -t 20 -i 2 -r" >> $desktoppath/$customer
sleep 30
ssh buee@$iperfserver < $killfile
sleep 10
cat $killfile
sudo kill -9 `ps aux | grep xterm | grep -v grep | awk '{print $2}' | head -1`
sudo kill -9 `ps aux | grep xterm | grep -v grep | awk '{print $2}' | head -1`
sudo kill -9 `ps aux | grep xterm | grep -v grep | awk '{print $2}' | head -1`

exit 0
Now my only problem is with the output of those commands to the file on my Desktop. It seems to not finish the output. And at the end of the command in section 2, which is bolded, has pertinent information at the very end, jitter, packet loss, etc. I did expand the sleep commands thinking maybe the processes were getting killed early, but there was absolutely no change, not even an extra line. Any thoughts on that one?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run SSH in the Background ? maas187 Linux - Networking 4 09-17-2009 12:27 AM
background process stops after exiting ssh session markraem Linux - Software 5 08-22-2007 06:59 AM
ssh -> perl -> spawn background proces hangs ssh session rhoekstra Programming 2 04-25-2006 02:05 AM
Command in background abdul_zu Linux - General 2 12-21-2005 01:41 PM
Running a program in the background - SSH ziggo0 Linux - Newbie 4 03-05-2005 02:30 PM


All times are GMT -5. The time now is 05:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration