LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-05-2009, 11:10 PM   #1
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
Bash variable expansion problem


This script is intended to allow you to simultaneously run a command on a set of remote hosts in a single gnome-terminal tabbed window. It runs it through screen so if it's a long process it's immune to network failures.

The command string gets built ok, but when it comes to executing the gnome-terminal command, it chokes with
Quote:
Argument to "--command/-e" is not a valid command: Text ended before matching quote was found for ". (The text was '"ssh')
If you copy/paste the "Running: gnome-terminal" line, it works as expected.

I'm pretty sure the problem is with the commandline variable expansion, but dont know what else to try.

Another thing I'd like to be able to do is keep the shell open after the command finishes. Right now, I just get "screen terminated" and the gnome-terminal tab says bye-bye.

Thanks in advance...

Code:
#!/bin/bash

if [ -z "$1" ]; then
  echo -e "Usage:\n  $0 \"command\"\n"
  exit 1
fi

hosts="localhost localhost localhost"
command="'$1'"
commandline=""

for h in $hosts; do
  commandline="$commandline --tab -e \"ssh -t root@$h screen -t $h -L $command\""
done

echo "Running: gnome-terminal $commandline"
/usr/bin/gnome-terminal "${commandline}"

Code:
$ ./screenIt "yum check-update"
Running: gnome-terminal  --tab -e "ssh -t root@localhost screen -t localhost -L 'yum check-update'" --tab -e "ssh -t root@localhost screen -t localhost -L 'yum check-update'"
Argument to "--command/-e" is not a valid command: Text ended before matching quote was found for ". (The text was '"ssh')

$ gnome-terminal  --tab -e "ssh -t root@localhost screen -t localhost -L 'yum check-update'" --tab -e "ssh -t root@localhost screen -t localhost -L 'yum check-update'"
 
Old 09-06-2009, 03:52 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Try
Code:
eval /usr/bin/gnome-terminal "${commandline}"
 
Old 09-06-2009, 03:54 AM   #3
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674

Original Poster
Blog Entries: 3

Rep: Reputation: 90
Bombdigity. That did the trick. Thanks!
 
  


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
variable expansion in bash coolhandluke1 Programming 4 01-09-2008 03:45 PM
Variable expansion in BASH champak Programming 5 11-26-2007 02:44 AM
Bash variable string expansion Reginald0 Linux - Software 5 02-13-2007 10:38 AM
Variable expansion inside of a bash script! A.S.Q. Linux - Newbie 4 09-29-2006 09:09 AM
bash script $n variable expansion cortez Programming 6 12-08-2003 04:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:42 PM.

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