if [ -s $File ] ; Whats wrong in this ??


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users if [ -s $File ] ; Whats wrong in this ??
# 1  
Old 08-20-2007
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 04:48 AM.. Reason: Edited email address and added code tags
# 2  
Old 08-20-2007
Why are you putting a dollar before the pathname in the if statement? Try:

Code:
if [ -s "/clocal/mqbrkrs/user/mqsiadm/sanjay/temp" ]

# 3  
Old 08-20-2007
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  
Old 08-20-2007
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  
Old 08-20-2007
MySQL

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 06:15 AM..
# 6  
Old 08-21-2007
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Whats wrong with the if else structure

whats wrong with the syntax, just the if-else part? Struggling for a bit with this now..I`m simply trying to increment 3 variables based on missing data, matches or mismatches for i and j ....... {for(i=1;i<=NF;i++) for(j=i+1;j<=NF;j++) { if(i=="" || $j=="") m++ ... (1 Reply)
Discussion started by: senhia83
1 Replies

2. UNIX for Dummies Questions & Answers

Whats wrong with this if-else

hi whats wrong in below?? CHECK=M10; if ; then echo "hello hi"; else echo "how are u hello hi"; fi I am getting error as ./test.sh: line 2: ' ./test.sh: line 2: M10: command not found ./test.sh: line 2: M10: command not found ./test.sh: line 2: M10: command not found (8 Replies)
Discussion started by: skyineyes
8 Replies

3. Homework & Coursework Questions

Whats wrong with the following

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: ls -ld htdocs drwxr-x--- 3 root root 8192 2006-11-19 10:41 htdocs How would a host administrator... (1 Reply)
Discussion started by: Larry_1
1 Replies

4. Shell Programming and Scripting

Whats wrong with my script?

I am trying to find a value within a properties file and declare it into a variable. Script below. I want the "memSize" to be the branch from the properties file. Right now it always tells me "Not found" What am I doing wrong? #!/bin/sh memsize =''; memSize=`sed '/^\#/d'... (8 Replies)
Discussion started by: vsekvsek
8 Replies

5. UNIX for Dummies Questions & Answers

whats wrong with this?

can anyone tell me why this code doesn't work how its supposed to, its the hangman game but it doesn't play how its supposed to #!/bin/bash NoAttempts="0" livesgiven="5" LivesRemain=$livesgiven LettersAttempted="" wordfile=words numwords=0 function menu() { clear cat << menu... (1 Reply)
Discussion started by: ferrycorsten73
1 Replies

6. Shell Programming and Scripting

Whats wrong with this IF condition?

I have four variables, dumpdata, defndata, compare1 and compare2 I want an IF statement condition which returns true when either dumpdata=defndata or (dumpdata<=compare1 and dumpdata>=compare2). But this is not working for me.. if (4 Replies)
Discussion started by: indianjassi
4 Replies

7. Shell Programming and Scripting

whats wrong with this code

ls -ld | grep $1 /etc/passwd | cut -d: -f6 i need see the content... (4 Replies)
Discussion started by: nadman123
4 Replies

8. Shell Programming and Scripting

tell me whats wrong with this

#! /bin/bash USAGE=" | ] if then echo "$USAGE" exit 1 fi while getopts lb: OPTION do case $(OPTION)in a) echo Hi there! exit 2;; b) echo hello o) OARG=$OPTARG;; \?)echo "$USAGE" ;; exit 2;; esac done shift `expr... (1 Reply)
Discussion started by: nadman123
1 Replies

9. Shell Programming and Scripting

tell me whats wrong in this?

#! /bin/bash head -5 $1 echo "remove $1 ?" read answer if then echo invalid answer elif rm $1 echo "$1 is deleted" elif then echo file is not deleted else echo "invalid answer" fi What i really want this to do is to ask to delete the file or not..it says something wrong... (1 Reply)
Discussion started by: nadman123
1 Replies

10. UNIX for Advanced & Expert Users

Whats wrong in this Script ???

PATH="/clocal/mqbrkrs/user/mqsiadm/sanjay" MAIL_RECIPIENTS="xyz@abc.com" Subject="File accessed in last minutes:" find $PATH -type f -amin -1 > temp.txt.$$ cat temp.txt.$$ | \ while read line do fuser -uV $line >> tempmail.txt done cat "$tempmail.txt" | mailx -s "$Subject"... (4 Replies)
Discussion started by: varungupta
4 Replies
Login or Register to Ask a Question