Scripiting quote and variable issues


 
Thread Tools Search this Thread
Operating Systems Solaris Scripiting quote and variable issues
# 1  
Old 10-29-2010
Scripiting quote and variable issues

Hello all I have an interesting problem here that I can't seem to figure out. Note this exists inside a script with the following header: m#!/usr/bin/sh

What I am trying to do is build an automounting script for USB hdd's, the idea is that the user plugs their drive in then runs the script. The script looks at dmesg and seaches for the lines that contain the drive information. From those lines I pull what USB location the drive is attached to, this is where I am having an issue:
Code:
 
 
rsh . -l int "autosu - root -c 'dmesg |grep pci@ |head -1 | cut -d/ -f 4 |cut -d' ' -f 1'"

The problem as far as I can figure is that I have single quotes inside of single quotes (inner marked in red), if I remove that cut statement I get exactly what I expect with the extra stuff on the back end I need to cut off; otherwise it brings in the entire line ignoring both cut statements.

In addition I am also trying to assign that to a variable inside the script something along the lines of this:
Code:
 
USBL='rsh . -l int "autosu - root -c 'dmesg |grep pci@ |head -1 | cut -d/ -f 4 |cut -d' ' -f 1' " '

Can anyone help me ....
# 2  
Old 10-29-2010
Sometimes with rsh/ssh/ssh2, I go with this style, which is more easily inspected before execution:
Code:
echo " . . ." | rsh there ksh

# 3  
Old 10-29-2010
DGPickett,

For reference ./animals looks like the following

cat,tiger,Fluffy
sheep,blackSheep,Spike
ect....

Am I to understand that placing a command such as this:

Code:
echo"grep cat ./animals"

will print the output of that command to the screen, so in this example I would get:
cat,tiger,Fluffy on the screen ?
# 4  
Old 10-29-2010
Which Operating System and version are you running?

Hard to follow a script which has a problem.
Can you post a sequence of commands which when typed at a keyboard output the value required?

Quote:
rsh . -l
Dodgy syntax. Is it safe to assume that the period is just the target hostname blanked out? Is the "dmesg" command to be executed on a remote computer?
# 5  
Old 10-29-2010
This might work:
Code:
rsh server -l int autosu - root -c "dmesg |grep pci@ |head -1 | cut -d/ -f 4 |cut -d' ' -f 1"

# 6  
Old 10-29-2010
Quote:
Originally Posted by striker0010
DGPickett,

For reference ./animals looks like the following

cat,tiger,Fluffy
sheep,blackSheep,Spike
ect....

Am I to understand that placing a command such as this:

Code:
echo"grep cat ./animals"

will print the output of that command to the screen, so in this example I would get:
cat,tiger,Fluffy on the screen ?
Well, yes, like this:
Code:
echo"grep cat ./animals" | rsh animal_host ksh

Essentially, you are generating a script dynamically, sending it over to the host for ksh to run. Don't forget something like ". ./.profile" if you need snvironment. I favor single quotes unless I want variable expansion, as they have fewer metacharacters. Parens are very nice for this, as you can mix in all sorts of commands, and as always, you can preview the created script for validity:
Code:
(
  echo '. ./.profile'
  echo 'grep cat ./animals'
 ) | rsh animal_host ksh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help/Advise please for converting space delimited string variable to comma delimited with quote

Hi, I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file. Example of the SQL will be For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING. I then concatenate... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

3. Windows & DOS: Issues & Discussions

Quote issues in VB.NET

Running into a small issue and not sure on the syntax to get around it... I need to execute: sc \\iamdc.grhq.XXX.com query "DirXMLRemote 8000" My issue though is the quotes. How to I keep the quotes only contained within the command instead of the logic using them? Not sure if I am... (1 Reply)
Discussion started by: LRoberts
1 Replies

4. Shell Programming and Scripting

replacing a quote in some lines with multiple quote fields

i want to replace mistaken quotes in line starting with tag 300 and relocate the quote in the correct position so the input is 223;25 224;20100428064823;1;0;0;0;0;0;0;0;8;1;3;9697;18744;;;;;;;;;;;; 300;X;Event:... (3 Replies)
Discussion started by: wradwan
3 Replies

5. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

6. Shell Programming and Scripting

variable issues

Hope someone can help me. I have 2 outputs 1 2 3 4 5 a b c d e basically, I'd like to loop thru these outputs and print out the results below 1/a 2/b 3/c 4/d 5/e Thanks, (16 Replies)
Discussion started by: kkkk
16 Replies

7. Shell Programming and Scripting

Quote and variable

The command line bellow works fine by itself. /opt/csw/bin/rsync -azq --delete -e "ssh -i /.ssh/ss" /home/ me@myaccount.storage.com:/home/ Now I would like to introduce some variable into it and make a .sh file such as bellow and it does not work anymore. I guess the part -e "ssh -i /.ssh/ss" has... (4 Replies)
Discussion started by: ngungo
4 Replies

8. Shell Programming and Scripting

Variable issues

Hey guys, I have just started getting into shell scripting, ive been self educating myself with it and have run into a snag. I am trying to make a very simple addition script. The script would be passed a number of parameters (numbers) and it would add them all together. I can do this fine... (2 Replies)
Discussion started by: bert682
2 Replies

9. Shell Programming and Scripting

Capturing Data between first quote and next quote

I have input file like RDBMS FALIURE UTY8703 'USER_WORK.TEST' .HIghest return code '12' I want to parse data which comed between first quote till next quote USER_WORK.TEST can you please suggest how to do that (4 Replies)
Discussion started by: scorp_rahul23
4 Replies

10. Shell Programming and Scripting

Problem with double quote and string variable

Hello, i have a file output.txt which contains a single line with a list of files with quotes : "file1.ext" "file2.ext" "file3.ext" In a shell script, I want to retrieve the line and use it as a variable in a command like : zip archive.zip $LIST I cant get it work. When I physically type... (6 Replies)
Discussion started by: mattemp
6 Replies
Login or Register to Ask a Question