The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

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 05:42 PM
tell me whats wrong with this nadman123 Shell Programming and Scripting 1 04-14-2008 08:58 PM
tell me whats wrong in this? nadman123 Shell Programming and Scripting 1 04-09-2008 10:11 PM
Whats wrong in this Script ??? varungupta UNIX for Advanced & Expert Users 4 08-31-2007 01:02 AM
whats wrong with this awk??? george_ Shell Programming and Scripting 5 04-04-2006 01:58 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-20-2007
Registered User
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 187
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 12:48 AM. Reason: Edited email address and added code tags
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-20-2007
robotronic's Avatar
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" ]
Reply With Quote
  #3 (permalink)  
Old 08-20-2007
Registered User
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 96
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
Reply With Quote
  #4 (permalink)  
Old 08-20-2007
Registered User
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 187
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
Reply With Quote
  #5 (permalink)  
Old 08-20-2007
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 285
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 02:15 AM.
Reply With Quote
  #6 (permalink)  
Old 08-20-2007
Registered User
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 96
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
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0