Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Script - empty variables

31 views
Skip to first unread message

contracer

unread,
Apr 23, 2013, 11:11:44 AM4/23/13
to
Hi,
Please help me solve this issue.
Script below shows empty variables:




#!/bin/ksh
set -x
Data=`date +"%Y%m%d%H%M"`
df -Pk | awk ' (NR > 1)' | awk '{print $(NF-2), $(NF-1), $NF}' | tr
'/' '#' | tr '%' ' ' | { while read Available_ Perc_used
Mount_point
do
Available=$(($Available_/1000))
echo "$Mount_point - $Available - $Perc_used"
touch /tmp/FS:$Mount_point:$Available:$Data
#if [[ $Perc_used -gt "90" && $Available -lt "800" ]]
if [[ $Perc_used -gt "19" && $Available -lt "154639" ]]
then

if [[ `ls -ltr /tmp/FS:$Mount_point:*| wc -l` -ge "3" ]]
then

ls -ltr /tmp/FS:$Mount_point:* | awk '{print $9}' | awk -F:
'{print$3}' | tail -3 | { while read A B C
do
echo $A
echo $B
echo $C


if [[ $A -gt $B && $B -gt $C ]]
then
echo " FS $Mount_point in a critical condition"
fi
done
}



fi

fi
done
}

Janis Papanagnou

unread,
Apr 23, 2013, 12:51:55 PM4/23/13
to
Am 23.04.2013 17:11, schrieb contracer:
> Hi,
> Please help me solve this issue.
> Script below shows empty variables:
>
>
>
>
> #!/bin/ksh
> set -x

Since you have set xtrace you should find the source of your empty
variables; so what's your problem?

Janis

> [...]

Barry Margolin

unread,
Apr 23, 2013, 2:27:54 PM4/23/13
to
In article
<e9c12ba5-270f-4dff...@y12g2000yqb.googlegroups.com>,
contracer <contr...@gmail.com> wrote:

> Hi,
> Please help me solve this issue.
> Script below shows empty variables:

Which ones?
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Kenny McCormack

unread,
Apr 23, 2013, 2:58:44 PM4/23/13
to
In article <barmar-A770EA....@news.eternal-september.org>,
Barry Margolin <bar...@alum.mit.edu> wrote:
>In article
><e9c12ba5-270f-4dff...@y12g2000yqb.googlegroups.com>,
> contracer <contr...@gmail.com> wrote:
>
>> Hi,
>> Please help me solve this issue.
>> Script below shows empty variables:
>
>Which ones?

Two things are clear about the OP:

1) The problem is almost certainly in the "variables set in a pipeline get
set in a subshell, and are thus not visible to the enclosing shells"
category.

2) The OP's approach is hopelessly complex and defies analysis.

--
Windows 95 n. (Win-doze): A 32 bit extension to a 16 bit user interface for
an 8 bit operating system based on a 4 bit architecture from a 2 bit company
that can't stand 1 bit of competition.

Modern day upgrade --> Windows XP Professional x64: Windows is now a 64 bit
tweak of a 32 bit extension to a 16 bit user interface for an 8 bit
operating system based on a 4 bit architecture from a 2 bit company that
can't stand 1 bit of competition.

contracer

unread,
Apr 23, 2013, 3:16:12 PM4/23/13
to
On Apr 23, 3:58 pm, gaze...@shell.xmission.com (Kenny McCormack)
wrote:
> In article <barmar-A770EA.14275423042...@news.eternal-september.org>,
> Barry Margolin  <bar...@alum.mit.edu> wrote:
>
> >In article
> ><e9c12ba5-270f-4dff-b6bc-a32f5de95...@y12g2000yqb.googlegroups.com>,
> > contracer <contrace...@gmail.com> wrote:
>
> >> Hi,
> >> Please help me solve this issue.
> >> Script below shows empty variables:
>
> >Which ones?
>
> Two things are clear about the OP:
>
> 1) The problem is almost certainly in the "variables set in a pipeline get
> set in a subshell, and are thus not visible to the enclosing shells"
> category.
>
> 2) The OP's approach is hopelessly complex and defies analysis.
>
> --
> Windows 95 n. (Win-doze): A 32 bit extension to a 16 bit user interface for
> an 8 bit operating system based on a 4 bit architecture from a 2 bit company
> that can't stand 1 bit of competition.
>
> Modern day upgrade --> Windows XP Professional x64: Windows is now a 64 bit
> tweak of a 32 bit extension to a 16 bit user interface for an 8 bit
> operating system based on a 4 bit architecture from a 2 bit company that
> can't stand 1 bit of competition.

Running this script I get this output:

#var - 4639 - 6
#ftp - 29308 - 1
#home#monitor - 2081 - 58
2083


2082


2081


But I don´t know why this script´s part don´t work:

Kenny McCormack

unread,
Apr 23, 2013, 5:34:00 PM4/23/13
to
In article <09806756-3e86-44c0...@b20g2000yqo.googlegroups.com>,
contracer <contr...@gmail.com> wrote:
...
>But I don“t know why this script“s part don“t work:
>
> if [[ $A -gt $B && $B -gt $C ]]
> then
> echo " FS $Mount_point in a critical condition"
> fi

Neither do we.
That's what I meant when I said that your script "defies analysis".

--

First of all, I do not appreciate your playing stupid here at all.

- Thomas 'PointedEars' Lahn -

contracer

unread,
Apr 24, 2013, 12:16:59 AM4/24/13
to
On Apr 23, 6:34 pm, gaze...@shell.xmission.com (Kenny McCormack)
wrote:
> In article <09806756-3e86-44c0-9b03-a6a4508b8...@b20g2000yqo.googlegroups.com>,contracer  <contrace...@gmail.com> wrote:
>
> ...
>
> >But I don´t know why this script´s part don´t work:
>
> >   if [[ $A -gt $B && $B -gt $C ]]
> >                    then
> >                    echo " FS $Mount_point in a critical condition"
> >                    fi
>
> Neither do we.
> That's what I meant when I said that your script "defies analysis".
>
> --
>
> First of all, I do not appreciate your playing stupid here at all.
>
>         - Thomas 'PointedEars' Lahn -

Is there a best way to do this ?

A=`ls -ltr /tmp/FS:$Mount_point:* | awk '{print $9}' | awk -
F ":" '{print$3}' | tail -3| tr '\n' ' '|awk '{print $1}'`
B=`ls -ltr /tmp/FS:$Mount_point:* | awk '{print $9}' | awk -
F ":" '{print$3}' | tail -3| tr '\n' ' '|awk '{print $2}'`
C=`ls -ltr /tmp/FS:$Mount_point:* | awk '{print $9}' | awk -
F ":" '{print$3}' | tail -3| tr '\n' ' '|awk '{print $3}'`

Thanks.

Janis Papanagnou

unread,
Apr 24, 2013, 5:55:42 AM4/24/13
to
Am 24.04.2013 06:16, schrieb contracer:
> On Apr 23, 6:34 pm, gaze...@shell.xmission.com (Kenny McCormack)
> wrote:
>> In article <09806756-3e86-44c0-9b03-a6a4508b8...@b20g2000yqo.googlegroups.com>,contracer <contrace...@gmail.com> wrote:
>>
>> ...
>>
>>> But I don“t know why this script“s part don“t work:
>>
>>> if [[ $A -gt $B && $B -gt $C ]]
>>> then
>>> echo " FS $Mount_point in a critical condition"
>>> fi
>>
>> Neither do we.
>> That's what I meant when I said that your script "defies analysis".
>>
>> --
>>
>> First of all, I do not appreciate your playing stupid here at all.
>>
>> - Thomas 'PointedEars' Lahn -
>
> Is there a best way to do this ?

Hard to tell; I'd say there is no "best" way. But there are certainly
dozens of ways that are ways better than what you've presented below.
Instead of enumerating all the deficiencies your code has - meanwhile
you should know anyway, since you're long enough here -, just tell us
what you want to do, provide samples as necessary, and we'll see...
0 new messages