LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03: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, 04: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, 06: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, 07: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



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-16-2009 11:27 PM
background process stops after exiting ssh session markraem Linux - Software 5 08-22-2007 05:59 AM
ssh -> perl -> spawn background proces hangs ssh session rhoekstra Programming 2 04-25-2006 01:05 AM
Command in background abdul_zu Linux - General 2 12-21-2005 12:41 PM
Running a program in the background - SSH ziggo0 Linux - Newbie 4 03-05-2005 01:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:06 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
Open Source Consulting | Domain Registration