Hey all,
first post here and as im sure once i ask my question.. you will all know that i am very new the shell scripting. I spend all of time in php, not shell.
I need to figure out a way to see if a shell varable has a value in it.
I have - SHELL="/bin/sh"
-
import EXT
-
import HOST
-
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
-
VHOME=`/home/vpopmail/bin/vuserinfo -d $EXT@$HOST`
-
FILE_SIZE=$SIZE
-
-
-
logfile "/var/log/qmail/maildrop.log"
-
set -x
-
log "==== BEGIN maildrop processing for $EXT@$HOST ==="
-
log "Home directory is $VHOME"
-
log "File size $SIZE"
-
-
if ( $VHOME eq ' ' )
-
{
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
log "=== EXIT === "
-
to "$VPOP"
-
}
-
my log files show entry's for $VHOME and $FILE_SIZE and $SIZE, but yet.. my script is saying that $VHOME is empty.
Knowing that my $VHOME has a value.. what am i doing wrong that is making it process the if statement? I have tried $VHOME = '', $VHOME =='', $VHOME eq '', $VHOME eq "".
17 2192
Hey all,
first post here and as im sure once i ask my question.. you will all know that i am very new the shell scripting. I spend all of time in php, not shell.
I need to figure out a way to see if a shell varable has a value in it.
I have - SHELL="/bin/sh"
-
import EXT
-
import HOST
-
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
-
VHOME=`/home/vpopmail/bin/vuserinfo -d $EXT@$HOST`
-
FILE_SIZE=$SIZE
-
-
-
logfile "/var/log/qmail/maildrop.log"
-
set -x
-
log "==== BEGIN maildrop processing for $EXT@$HOST ==="
-
log "Home directory is $VHOME"
-
log "File size $SIZE"
-
-
if ( $VHOME eq ' ' )
-
{
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
log "=== EXIT === "
-
to "$VPOP"
-
}
-
my log files show entry's for $VHOME and $FILE_SIZE and $SIZE, but yet.. my script is saying that $VHOME is empty.
Knowing that my $VHOME has a value.. what am i doing wrong that is making it process the if statement? I have tried $VHOME = '', $VHOME =='', $VHOME eq '', $VHOME eq "".
Hi,
You might try -eq instead of just eq.
Hope this helped.
no. that did not fix my issue.
[HTML]if ( $VHOME -eq "" )[/HTML]
Okay, now I see the problem. The clue was that you normally operate in PHP. The if statement that you have is fine in PHP, but shell has a different structure. Try this:
[code]
if [ $VMHOME = "" ]
then
<what you want to do if VMHOME not set>
fi
[\CODE]
Spaces around the braces ( [ ] ) are required. I tried this on my own system and it works reliably.
i now get an Syntax_error_after_if/ in my log files.
my code is as follows. - if [ $VHOME == '' ]
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
log "=== EXIT === "
-
to "$VPOP"
-
fi
i now get an Syntax_error_after_if/ in my log files.
my code is as follows. - if [ $VHOME == '' ]
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
log "=== EXIT === "
-
to "$VPOP"
-
fi
You don't have the 'then' in your if statement. It comes right after the if line: -
if [ <expession> ]
-
then
-
<statements>
-
fi
-
May also be written as:
[code]
if [ <expression> ] ; then
<statements>
fi
[\CODE]
Also, you will probably get some errors from your log statements. Unless you have written 'log' as a procedure call somewhere else in your shell procedure, you will get an error on each of the lines starting with 'log' and for sure on the line starting with 'to'.
In your if test expression, you are using a PHP equals. Only a single equal sign (=) is used in shell for string comparison.
this is my script.
this is my script. - #! /bin/sh
-
import EXT
-
import HOST
-
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
-
VHOME=`/home/vpopmail/bin/vuserinfo -d $EXT@$HOST`
-
FILE_SIZE=$SIZE
-
-
-
logfile "/var/log/qmail/maildrop.log"
-
log "==== BEGIN maildrop processing for $EXT@$HOST ==="
-
log "Home directory is $VHOME"
-
log "File size $SIZE"
-
-
if [$VHOME = '' "]; then
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
then
-
log "=== EXIT === "
-
then
-
to "$VPOP"
-
fi
log is defined. in my script, im using 1 = sign, and i have placed my then after the ;
the script is still telling me there is an error after if on line 14.
this is my script.
this is my script. - #! /bin/sh
-
import EXT
-
import HOST
-
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
-
VHOME=`/home/vpopmail/bin/vuserinfo -d $EXT@$HOST`
-
FILE_SIZE=$SIZE
-
-
-
logfile "/var/log/qmail/maildrop.log"
-
log "==== BEGIN maildrop processing for $EXT@$HOST ==="
-
log "Home directory is $VHOME"
-
log "File size $SIZE"
-
-
if [$VHOME = '' "]; then
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
then
-
log "=== EXIT === "
-
then
-
to "$VPOP"
-
fi
log is defined. in my script, im using 1 = sign, and i have placed my then after the ;
the script is still telling me there is an error after if on line 14.
Look at the extra quote character just before the right brace. Also, what are the extra 'then' lines doing in the script on lines above and below the 'log "=== EXIT' line?
Look at the extra quote character just before the right brace. Also, what are the extra 'then' lines doing in the script on lines above and below the 'log "=== EXIT' line?
- import EXT
-
import HOST
-
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
-
VHOME=`/home/vpopmail/bin/vuserinfo -d $EXT@$HOST`
-
FILE_SIZE=$SIZE
-
-
-
logfile "/var/log/qmail/maildrop.log"
-
log "==== BEGIN maildrop processing for $EXT@$HOST ==="
-
log "Home directory is $VHOME"
-
log "File size $SIZE"
-
-
if [$VHOME = '']; then
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
log "=== EXIT === "
-
to "$VPOP"
-
fi
same error. _Syntax_error_after_if/ is it worth saying that my OS is fedora 8?
I haven't done any shell scripting in ages, but I do recall a -z string function to check if the length of the variable is zero. http://en.wikipedia.org/wiki/Test_(Unix) -
if [ -z "$variable" ] ; then
-
echo "\$variable is not set."
-
fi
Fedora's sh should execute like UNIX/LINUX sh, so I don't think that is the cause. Are you sure that you have spaces between the braces? I'm going to use underscore instead of space below to illustrate where spaces are required: -
#example showing underscores instead of spaces
-
if_[_$VMHOME_=_''_]_;_then
-
-
#example showing spaces
-
if [ $VMHOME = '' ] ; then
-
-
This shows how to construct the expression so that VMHOME would always have a value but will still detect if it was empty. Consider this: -
if [ "X$VMHOME" = "X" ] ; then
-
<do your log stuff here>
-
fi
-
This permits checking for an empty VMHOME, but will keep the shell from complaining if the variable is not set. I also agree with WinblowsMe's post that a -z test option is available.
Robbie, do what bykwzpz said and put spaces around the brackets and add double-quotes to the variable. - import EXT
-
import HOST
-
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
-
VHOME=`/home/vpopmail/bin/vuserinfo -d $EXT@$HOST`
-
FILE_SIZE=$SIZE
-
-
logfile "/var/log/qmail/maildrop.log"
-
log "==== BEGIN maildrop processing for $EXT@$HOST ==="
-
log "Home directory is $VHOME"
-
log "File size $SIZE"
-
-
if [ "$VHOME" = "" ] ; then
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
log "=== EXIT === "
-
to "$VPOP"
-
fi
Or try -
if [ -z "$VHOME" ] ; then
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
log "=== EXIT === "
-
to "$VPOP"
-
fi
thanks everyone for all the help so far! but it's still not working for me... - #! /bin/sh
-
import EXT
-
import HOST
-
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
-
VHOME=`/home/vpopmail/bin/vuserinfo -d $EXT@$HOST`
-
FILE_SIZE=$SIZE
-
-
-
logfile "/var/log/qmail/maildrop.log"
-
log "==== BEGIN maildrop processing for $EXT@$HOST ==="
-
log "Home directory is $VHOME"
-
log "File size $SIZE"
-
-
if [ -z "$VHOME" ] ; then
-
log "ERROR: VHOME isn't set, falling back to vdelivermail"
-
log "=== EXIT === "
-
to "$VPOP"
-
fi
i made sure that there are spaces in my file config, and that im using the "" around my $VHOME value. log files still say ":_Syntax_error_after_if/" on line 14 which is the first time the If statement present.
Hi Robbie,
Try this script in a separate file. I called mine 'mytest'. When you have created this script, use chmod +x to make it executable. Then execute it using ./mytest from your command prompt.
If you get the message "Error - NO VHOME", then the structure of the if statement is sound. The syntax error is somewhere else - perhaps in some of the statements within the if statement. If you don't get the message, then there may be a problem prior to the if statement that does not affect anything until the if statement is encountered. -
#!/bin/sh
-
-
VHOME=""
-
-
if [ -z "$VHOME" ] ; then
-
-
echo "Error - no VMHOME"
-
exit 1
-
-
fi
-
-
echo "ERROR - VHOME IF TEST FAILED"
-
-
exit 0
-
i did as u suggested.. and it said that ERROR VHOME IF TESTED FAILED.
Hi Robbie,
Try this script in a separate file. I called mine 'mytest'. When you have created this script, use chmod +x to make it executable. Then execute it using ./mytest from your command prompt.
If you get the message "Error - NO VHOME", then the structure of the if statement is sound. The syntax error is somewhere else - perhaps in some of the statements within the if statement. If you don't get the message, then there may be a problem prior to the if statement that does not affect anything until the if statement is encountered. -
#!/bin/sh
-
-
VHOME=""
-
-
if [ -z "$VHOME" ] ; then
-
-
echo "Error - no VMHOME"
-
exit 1
-
-
fi
-
-
echo "ERROR - VHOME IF TEST FAILED"
-
-
exit 0
-
sorry.. when i copy and paste your code. it works. but i c no difference in what you typed then i do.. hrm.
it's SOLVED!!!!!! -
SHELL="/bin/sh"
-
import EXT
-
import HOST
-
VPOP="| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
-
VHOME="/home/vpopmail/domains/$HOST/$EXT"
-
MAILDIR1="$VHOME/Maildir"
-
-
logfile "/var/log/qmail/maildrop.log"
-
log "==== BEGIN maildrop processing for $EXT@$HOST ==="
-
log "Mail directory is $MAILDIR1"
-
log "file size is $SIZE"
-
-
#check size then process the email through dspam.
-
if ( $SIZE < 256000 )
-
{
-
log "file is less then 250k so im going to process it!"
-
xfilter '/ops/dspam/bin/dspam --deliver=innocent,spam --user $EXT@$USER --debug --mode=teft --feature=noise,whitelist --stdout -p -m'
-
}
-
-
#check for larger file size here
-
if ( $SIZE > 256000 )
-
{
-
log "File is more then 250K, so Im going to deliver it!"
-
to "$VPOP"
-
}
-
-
#check to see if message is spam, and if so.. put it where it belongs, else put it in the new folder.
-
if (/^X-DSPAM-Result: Spam/)
-
{
-
log "message was spam.. So i moved it to there spam folder"
-
log "spam folder is $VHOME/Maildir/.Spam/new"
-
to "$MAILDIR1/.Spam/"
-
}
-
-
if (/^X-DSPAM-Result: Innocent/)
-
{
-
log "message was not spam.. So i moved it to there inbox"
-
log "ham folder is $VHOME/Maildir/new"
-
to "$MAILDIR1"
-
}
-
-
log "all if's failed. So im delivering the meaage"
-
to "$VPOP"
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Bentley |
last post by:
John Bentley:
INTRO
The phrase "decimal number" within a programming context is ambiguous. It could
refer to the decimal datatype or the related but separate concept of a generic
decimal number....
|
by: Shahid Juma |
last post by:
Hello All,
This may be a trivial question, but I was wondering how can you determine if
a value contains an Integer or Float. I know there is a function called
IsNumeric, however you can't...
|
by: Christopher W. Douglas |
last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a
method that handles several events, such as closing a form and changing the
visible status of a form. I have some code...
|
by: Edward |
last post by:
I have the following function to determine if a form is loaded:
Public Function modIsloaded(ByVal vstrFormName As String) As Boolean
' Error handling removed for concision
' Determine if...
|
by: Siegfried Heintze |
last post by:
This program works fine on my desktop when I grant full control of the
MSAccess database to everyone. However, when I put it on my hosting service
with no impersonation, I now get this error (see...
|
by: Bob Day |
last post by:
VS 2003, sql
How do you determine the data type of a column if its value is DBNull?
1)Table:
Column1 STRING non-nullable
2) Fill to a DataSet via DataAdapter
3) dim Data_Type_Is...
|
by: Developer in California |
last post by:
I am working on developing a generic Web framework using Master Pages in
ASP.NET 2.0. What I have done is created a PageRenderer class which has a
public method which will retrieve the path of the...
|
by: semedao |
last post by:
Hi all,
I view many posts about this issue , the connected property does not tell us the current status of the socket.
based on couple of suggestions of msdn , and some article here , I try to...
|
by: Jana |
last post by:
Greetings Access Gurus! I am working on an app to send batch
transactions to our bank, and the bank requires that we place an
effective date on our files that is 'one business day in the future,...
|
by: tks423 |
last post by:
How can I determine the values of a listbox, both unselected or
selected after submitting the form:
Code:
<select name="sel1" size="10" multiple="multiple">
<? PHP code populates listbox ?>...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |