[wplug] Bash subshell return value
Gary Morrow
gary.morrow at ansys.com
Mon Aug 25 11:30:24 EDT 2003
I'm not a Bourne shell expert (I would have done it in Perl) but I see
some problems:
Wise, Jeremey wrote:
>I am trying to write a script to run a sync of two server vi scp. (no rsync
>is not an option as the other server guys will not load rsync:>) I have RTFM
>but even though I know it is some stupid user error I am not seeing the
>forest for the trees kind of thing.
>
>
>Here is the basic structure.
>**************
>#!/bin/bash
>#!/bin/bash
># Variables list
>Fileuplist=/root/scpcopyup.list
>Filedownlist=/root/scpcopydown.list
>FilesSynced=/root/filesynced.list
>
># SCP Up to IDX
>while [ -s $Fileuplist ]
> do
># file ./root/firstline.pl is a perl script which cuts the first line out of
>a file checks if it is a directory
># if not directory sends it to standard out. EX: firstline.pl /root/scpcopyup.list -> ./etc/fstab. (first line)
>
>Currentfile=(/root/firstline.pl $Fileuplist)
>
It's not parens, it's backtics. You need:
Currentfile=`/root/firstline.pl $Fileuplist`
># test of variable output
>echo $Currentfile
> rc=$?
>
since $? is the exit status of the previous command (echo $Currentfile)
you will always get 0 (success)
> if [ $rc -ne 0 ] ; then
> printf "Error reading file"
> exit 50
> else
> scp user at acme.com:/$Currentfile .
>
$rc is still the exit value of the echo command (echo $Currentfile).
still always 0
> if [ $rc -ne 0 ] ; then
> echo "$Currentfile failed to copy up." >> $FileSynced
> exit 51
> else
> echo "$Currentfile successfully copied." >> $FilesSynced
> fi
> fi
>done
>
># SCP Down to ACME.com
>.....
>****************
>The out put is as follows
>[root at toybox root]# ./test.scp
>/root/firstline.pl
>**************
>Yet, if I run the command directly the correct output is replied:
>
>[root at toybox root]# ./firstline.pl /root/scpcopyup.list
>/etc/lilo.conf.anaconda[root at toybox root]#
>*****************
>
>I thought using () quotes would run the command in the quotes in a subshell
>and simply return results? I have tried (( ...)) which should again run
>(ignoring variables set so I replaced with explicit paths to variables) and
>this had no effect
>
>Any help would be appreciated.
>
>Thanks,
>
>Jeremey Wise (440)-519-6006
>(CNE,MCSE,CSE)
>Pioneer-Standard Electronics, Inc
>wisej at pios.com
>
>IBM ED PACK -Part # SB033 $4,500 ... SP Discount 11%
>IBM ED CARD - Part # SB218 $8,995 ... SP Discount 8.5%
>
>_______________________________________________
>wplug mailing list
>wplug at wplug.org
>http://www.wplug.org/mailman/listinfo/wplug
>
>
>
>
--
Gary Morrow
Integ. Testing Grp.
Ansys Inc.
gary.morrow at ansys.com
724-514-2978
More information about the wplug
mailing list