The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
xargs: missing quote? AbhishekG Shell Programming and Scripting 2 06-04-2008 10:18 AM
escaping single quote javeed7 Shell Programming and Scripting 3 04-02-2008 06:36 AM
single quote dreams5617 Shell Programming and Scripting 2 12-01-2007 03:37 AM
single or double quote in SED asami Shell Programming and Scripting 2 07-17-2006 04:03 AM
Replacing a single quote rjsha1 Shell Programming and Scripting 3 12-23-2005 10:55 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 11-01-2006
Janus Janus is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 18
Lightbulb Don't Quote Me On This...

Korn Shell Scripting on Solaris 9

Hello, this is my first post, I figure I share a problem and how I fixed it as well as ask a question that I'm currently stuck on. A version of "Give a Penny" "Take a Penny"

First Problem - I'm currently writing an automated version of one of the two types of Audit script for the company I work for (Myself and a coworker are split between AIX and SunOS. I have SunOS and he's doing AIX). We can do this manually, but why manually do these when you can have a script answer the questions for you in a quick and efficient manner? So I went to town and put together a nice script that worked for this first type of Audit. The issue was once I took it off of one SunOS server and onto another, I'd see issues arise. I therefore went back to the drawing board and am now in the process of redoing the scripts to "hopefully" be compliant throughout our company SunOS servers. In revising the script, I came across the following command in one of my functions.

The purpose of this function is to check the root's profile for 2 strings to be present. I have two different commands for the two different strings. The second command works fine trying to find the string "umask 027", the first string however, as you will see, has a few ticks, quotes, and double quotes to throw a nice wrench into the Unix gearworks. NOTE:There's a difference between the two strings in the egrep, look for the space after the ; before the "export".

I had the following command within my function:

rootpathvar1=`cat /.profile | egrep 'PS1="`/bin/hostname`#"; export PS1|PS1="`/bin/hostname`#";export PS1' | wc -l`

When the script ran, I wouldn't get any response (below this command I have an "if" statement having the ( number > 0 ) checked). I debugged and put an "echo $rootpathvar1" after the command and it echoed out a "0". Exiting the script and running the command on its own:

cat /.profile | egrep 'PS1="`/bin/hostname`#"; export PS1|PS1="`/bin/hostname`#";export PS1'

I received the output of:
PS1="`/bin/hostname`#";export PS1

First Problem's Answer:
If it worked there, I should have had a value of 1 in the script, so back to the drawing board I went. After looking it over, it became evident that the problem was with the "command ticks", aka the ` symbols:

rootpathvar1=`cat /.profile | egrep 'PS1="`/bin/hostname`#"; export PS1|PS1="`/bin/hostname`#";export PS1' | wc -l`

Even though I had the ' quotes in (which I gathered from resources to always give the literal meaning of what comes after it, my thinking being that everything after the ' to be a string until it came to the enclosing ') place, the ` outside the command and the ` inside the command clashed. I came across the power of \. It encloses the character after it as if it were its own quotes (please correct me if I'm wrong). So that command from above became:

rootpathvar1=`cat /.profile | egrep 'PS1="\`/bin/hostname\`#"; export PS1|PS1="\`/bin/hostname\`#";export PS1' | wc -l`

Running the script now produced the result I desired and I lived happily ever after....or so I thought.

Problem # 2, aka My Real Thorn In My Side
After that problem above, I was smooth sailing cruising through the rest of the script, editing and tweaking and fixing. I came to about 4 functions away from being done when I encountered the problem which is currently plaguing me. I am looking within the /var/spool/cron/crontabs/sys file for the following string:
0,20,40 * * * * /usr/lib/sa/sa1 (don't worry, my eyes rolled when seeing how I had to tackle this one as well)

I figured grep to the rescue and all would be good, I was wrong. I took this out to the command line to try and fix first.

If I enter the following command:

cat /var/spool/cron/crontabs/sys | grep "0,20,40 * * * * " (yes include the space after the last *)

Results = 0,20,40 * * * * /usr/lib/sa/sa1 (This is a good thing, but not my grep only contained everything up until the "/" character)

If I do the second half of the grep string:

cat /var/spool/cron/crontabs/sys | grep "/usr/lib/sa/sa1"

Results = 0,20,40 * * * * /usr/lib/sa/sa1 (Again, great, but I'm missing the first half of the grep string).

As soon as I put it all together:

cat /var/spool/cron/crontabs/sys | grep "0,20,40 * * * * /usr/lib/sa/sa1"

It shakes a finger at me and shows me no results, it doesn't work. I debugged and slowly but surely I started with doing the command, character by character.

cat /var/spool/cron/crontabs/sys | grep "0", then
cat /var/spool/cron/crontabs/sys | grep "0," so on and so forth until I get to

cat /var/spool/cron/crontabs/sys | grep "0,20,40 * * * * /"

Once the / is placed within the string, it no longer works. I've tried to switch the " with ' surrounding the grep string and that doesn't work. I've tried to put the \ character before it (i.e. "\/") to see if it takes it as a / character and not it's special meaning, but that doesn't work.

I have perused the Net and these forums as well to see if the question of this type of problem occuring, but to no avail. I know this was lengthy, but I hope in the process of answering this question, my Q&A at the beginning my help others working on strings and greps.

Thank you all for your time and patience in reading this short novella, and thank you for what help you can supply.

~Ryan
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0