LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 03:51 AM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

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, 03:55 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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 04:04 AM.
 
2 members found this post helpful.
Old 02-26-2012, 03:57 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 04:01 AM   #4
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

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, 04:03 AM   #5
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

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, 04:06 AM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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, 04:07 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 04:13 AM   #8
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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, 04:22 AM   #9
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

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, 04:26 AM   #10
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

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, 04:28 AM   #11
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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 04:30 AM.
 
1 members found this post helpful.
Old 02-26-2012, 04:40 AM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 05:00 AM   #13
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

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, 05:01 AM   #14
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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, 05:03 AM   #15
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

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



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 01:58 AM
Check to see if wireless N is working Lucard Linux - Networking 2 03-11-2010 12:00 AM
How can I check bluetooth is working? Simmo512 Slackware 8 01-30-2008 06:35 AM
How to check if iptables is working borrrden Linux - Security 10 09-20-2004 08:55 PM
How to check if ACPI working ar1 Linux - Laptop and Netbook 0 08-05-2004 02:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:13 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
Open Source Consulting | Domain Registration