LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-26-2012, 04:51 AM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Rep: Reputation: 0
Unhappy -z check is not working :(:(


Hi,

I am trying this.
if [[ -z "${RELEASE}" ]]; then
echo "RELEASE value not supplied";
exit 1
fi

a very small and simple piece of code but while executing it doesn't do echo but says exit 1

where is the mistake???
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-26-2012, 04:55 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Could we kindly see all of the code so we can get the feel what you are exactly trying to do? And also, what shell are you using? One last thing I can tell is that it should be $() instead of ${}.

Edit - Nevermind on the last part..... Still waking up.....

Last edited by corp769; 02-26-2012 at 05:04 AM.
 
2 members found this post helpful.
Old 02-26-2012, 04:57 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Not sure how you actually tried, but this works like a charm:
Code:
#!/bin/bash

if [[ -z "${RELEASE}" ]]
then
  echo "RELEASE value not supplied"
  exit 1
fi

echo "RELEASE is supplied"

exit 0
Test run:
Code:
$ chmod 750 tst.sh
$ ./tst.sh
RELEASE value not supplied
$
Please elaborate on your problem.
 
2 members found this post helpful.
Old 02-26-2012, 05:01 AM   #4
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
@drunna thanks for that, I shall try but I want to make my understanding very clear about my code is not working

@corp769 here is full code.
#!/bin/ksh

set -x
. /app/scm/dropzone/$RELEASE/release_record.sh

#echo $CI
#echo $ENVID
#echo $CCB_ENVNAME

if [[ -z "${RELEASE}" ]]; then
echo "RELEASE value not supplied"
exit 1
fi

if [[ -z ${CI} ]];then
exit 1
fi

if [[ -z ${CCB_ENVNAME} ]]; then
exit 1
fi

export TAR_FILENAME=$CCB_ENVNAME_PRE_$RELEASE_`hostname`.tar.gz

if [[ -f ${TAR_FILENAME} ]] ; then
echo "App tar ball exist please check backup directory"
fi


# ***************************************************************
# * *
# * Create Tarball file and put it in the backup directory *
# * *
# ***************************************************************
date
tar cvf - /app/ccb/$ENV_NAME | gzip > /app/scm/dropzone/Backups/ccb/$CI/$TAR_FILENAME
if [[ $? -ne 0 ]];then
exit 1
fi
 
Old 02-26-2012, 05:03 AM   #5
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
all what I want to do is check arguments like release,ci envid if they are not supplied build should fail with meaningfull message if these are present then it should check if that.tar.gz file is present(if present build should fail) if not it should proceed with doing tar of entire directory.

Cheers
 
Old 02-26-2012, 05:06 AM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Well just like druuna, works for me too. Noticed you are using ksh though... Have you tried using a different shell though, like bash, just to rule it out?
 
1 members found this post helpful.
Old 02-26-2012, 05:07 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi again,

If I run your posted code (post #4), it does what it is supposed to (I had to comment out the . /app/scm/dropzone/$RELEASE/release_record.sh part):
Code:
$ ./tst.sh
+ [[ -z '' ]]
+ echo 'RELEASE value not supplied'
RELEASE value not supplied
+ exit 1
You do realize that all the entries that are prepended with + are there because of the set -x statement in the script?
 
1 members found this post helpful.
Old 02-26-2012, 05:13 AM   #8
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Druuna beat me to it, as I was replying to another thread.... I noticed that as well, and that was the first thing that popped up in my head. Just like he said, are you getting " + exit 1" in your terminal?
 
1 members found this post helpful.
Old 02-26-2012, 05:22 AM   #9
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
corp769 and drunna

First of all thank you for your support.

yes I am aware of "+ exit 1" output which I am getting because trace is ON that is set -x.

I am not sure what shell plays the role but same code but if I change /ksh value to /bash there is an interesting observation.
Output changes from just + exit 1 to
{code}
+ [[ -z 1.9.0.6.6.12 ]]
+ [[ -z '' ]]
+ exit 1
{code}

Yes it is doing what is supposed to meaning, build fails but I am not sure of two statements.

echo "RELEASE value not supplied"
exit 1

why it just does exit 1, it should display some meaning message as well?
 
Old 02-26-2012, 05:26 AM   #10
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
One more thing if I change from {} to ()
so
if [[ -z "$(RELEASE)" ]]; then
echo "RELEASE value not supplied"
exit 1
fi

it gives output as

line 10: RELEASE: command not found
+ [[ -z '' ]]
+ echo 'RELEASE value not supplied'
RELEASE value not supplied
+ exit 1

Now why the heck it is looking for RELEASE as command? it is displaying meaning output though which is good.
 
Old 02-26-2012, 05:28 AM   #11
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Read my edit in that post, I said to nevermind that.... When I wrote that, I was still waking up, and apparently my brain thought that you were trying to execute that variable for some reason. My bad!

Just curious... What distro, and version of both bash and ksh are you using?

Last edited by corp769; 02-26-2012 at 05:30 AM.
 
1 members found this post helpful.
Old 02-26-2012, 05:40 AM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Your code does have some strangeness:

You first parse a file which contains the $RELEASE variable (this line: . /app/scm/dropzone/$RELEASE/release_record.sh), after that is done you check for the existence of $RELEASE. If $RELEASE isn't set, the parsing part will give an error message and the script will exit at that point. No need to check for $RELEASE after the fact......

What happens if you give the following a try:
Code:
#!/bin/ksh

set -x

if [[ -z "${RELEASE}" ]]
then
  echo "RELEASE value not supplied"
  exit 1
fi

. /app/scm/dropzone/$RELEASE/release_record.sh

#echo $CI
#echo $ENVID
#echo $CCB_ENVNAME

if [[ -z "${CI}" ]]
then
  echo "CI value not supplied"
  exit 1
fi

if [[ -z "${CCB_ENVNAME}" ]]
then
  echo "CCB_ENVNAME value not supplied"
  exit 1
fi

export TAR_FILENAME="$CCB_ENVNAME_PRE_$RELEASE_`hostname`.tar.gz"

if [[ -f "${TAR_FILENAME}" ]]
then
  echo "App tar ball exist please check backup directory"
  exit 1
fi

echo "All is well"
exit 0
BTW: Do provide the info corp769 asked for. Also include the output of the following command:
Code:
file <name_of_script>
 
2 members found this post helpful.
Old 02-26-2012, 06:00 AM   #13
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
drunna I agree with you, that is completely incorrect logic.
First I am parsing file to read it and source release variables and then checking for RELEASe value ! not good programming mate

we are using redhat os.
bash on source (build)server is
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
version sh (AT&T Research) 93s+ 2008-01-31
Red Hat Enterprise Linux Server release 5.3 (Tikanga)

on target server
I can tell easily bash version
GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.

I am unable to tell ksh version as that is what I am unable to determine.

OS
Red Hat Enterprise Linux AS release 4 (Nahant Update 7)
 
Old 02-26-2012, 06:01 AM   #14
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
I do recommend upgrading to the latest and greatest, if you can. Are you a subscribed user? I say that because me and druuna aren't having problems with this...
 
1 members found this post helpful.
Old 02-26-2012, 06:03 AM   #15
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
@drunna

file tar_ball.sh
tar_ball.sh: Korn shell script text executable
file ccb_create_tarball.sh
ccb_create_tarball.sh: Bourne-Again shell script text executable

---------- Post added 02-26-12 at 10:04 PM ----------

@corp769 u mean bash and kron shell version?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check CPU - Red Hat - how to check if CPU working correctly ? dlugasx Linux - Server 8 07-28-2011 02:58 AM
Check to see if wireless N is working Lucard Linux - Networking 2 03-11-2010 01:00 AM
How can I check bluetooth is working? Simmo512 Slackware 8 01-30-2008 07:35 AM
How to check if iptables is working borrrden Linux - Security 10 09-20-2004 09:55 PM
How to check if ACPI working ar1 Linux - Laptop and Netbook 0 08-05-2004 03:32 AM


All times are GMT -5. The time now is 06:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration