The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
whats wrong with this code nadman123 Shell Programming and Scripting 4 04-15-2008 08:42 PM
tell me whats wrong with this nadman123 Shell Programming and Scripting 1 04-14-2008 11:58 PM
tell me whats wrong in this? nadman123 Shell Programming and Scripting 1 04-10-2008 01:11 AM
Whats wrong in this Script ??? varungupta UNIX for Advanced & Expert Users 4 08-31-2007 04:02 AM
whats wrong with this awk??? george_ Shell Programming and Scripting 5 04-04-2006 04:58 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-20-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
if [ -s $File ] ; Whats wrong in this ??

Code:
Subject="QM DOWN : Daily Monitoring Report "
MAIL_RECIPIENTS="someone@some.where"
dspmq > tempdspmq.txt.$$
cat tempdspmq.txt.$$
sed -n '/Running/p' tempdspmq.txt.$$ > temp
cat temp
if [ -s "$/clocal/mqbrkrs/user/mqsiadm/sanjay/temp" ]
then
echo "1 DONE"
cat "$/clocal/mqbrkrs/user/mqsiadm/sanjay/temp" | mailx -s "$Subject" $MAIL_RECIPIENTS
echo "2 DONE"
fi
echo "3 DONE"
---------------

Whats wrong in this script ?
I think its not executing the if [ ] statement.
NOTE: you can replace any other command with 'dspmq' that i have written in my script.

Please help ASAP.

Last edited by vino; 08-20-2007 at 03:48 AM.. Reason: Edited email address and added code tags
  #2 (permalink)  
Old 08-20-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Why are you putting a dollar before the pathname in the if statement? Try:

Code:
if [ -s "/clocal/mqbrkrs/user/mqsiadm/sanjay/temp" ]
  #3 (permalink)  
Old 08-20-2007
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
what u mean by $/clocal/mqbrkrs/user/mqsiadm/sanjay/temp

I mean if temp is ur file name, why using "$"? the absolute path is enough.
and if ur file exists in temp directory, use the absolue path inside the quotes.

anchal
  #4 (permalink)  
Old 08-20-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Another Q

thanks buddy.

if [ -s "/clocal/mqbrkrs/user/mqsiadm/sanjay/temp" ]
Can you tell me the reason, why should not we put $ before the name of file, in such statements. ?

In the cat command that i have used, its working in the same manner as you said. Why the $ is creating problem, even here i want contenty of temp file should be given to the pipe.
cat "/clocal/mqbrkrs/user/mqsiadm/sanjay/temp" | mailx -s "$Subject" $MAIL_RECIPIENTS
  #5 (permalink)  
Old 08-20-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Thumbs up

Varun,
If you are using a variable and want to acces the value of the variable then only you need to put $ sign otherwise not needed.

suppose

path=/usr/bin/this

if you are using this path variable in ur script then you have to put a $ sign before that to access the value.
otherwise directly you can hardcode that value without the $ sign as you did in your if statement.

Thanks
Namish

Last edited by namishtiwari; 08-20-2007 at 05:15 AM..
  #6 (permalink)  
Old 08-21-2007
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
the cat command itself displays the content of the file...
"cat test" will display the file content of test. and using pipe u are redirecting the contents to the next command ( mail in ur case).

for usage of $ follow the same rule as namishtiwari told.

so just for example and considering ur case
u define a variable like this
file_path=/clocal/mqbrkrs/user/mqsiadm/sanjay/temp

so in ur test command u need to use the value of the variable file_path which is the actual path of ur file. so u have to use "$file_path"

so ur command 'll be like this
if [ -s "$file_path" ]


its always a good idea of using variables instead of hardcoding the paths.
for both security as well as reusing of the code.


anchal
Sponsored Links
Closed Thread

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 06:18 AM.


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