Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my alias's do't work in for loop.....

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I'm having problem using my aliases within a a for loop...

Bash....

for server in `[ -f $* ] && cat $* || echo $*`
do
##### Generate the data.....
$server "/usr/openv/volmgr/bin/vmoprcmd -devmon ds -no_format" 2>/dev/null > /home/pubuntu/${server}_drivestatus.txt
$server "/usr/openv/volmgr/bin/vmoprcmd -devmon hs" 2>/dev/null > /home/pubuntu/${server}_hoststatus.txt

##### Now send out the data.....
echo " "
echo "########## ${server} ##########"
echo " "
/bin/sed '1,4d' /home/pubuntu/${server}_hoststatus.txt| grep -iv connection
echo " "
/usr/bin/awk '{print $6, $3, $7, $8, $10, $36}' /home/pubuntu/${server}_drivestatus.txt |awk '{ if (NF > 5) print}'| sort
echo " "

done

I can use my aliases within the script... but not in the for loop...

Any idea's

Thanks....

Joe Despres
 
Under some circumstances, the body of a [tt]for[/tt] loop can be a subprocess. Aliases are not inherited by subprocesses like exported variables are.

If you need to use an alias, define it again as the first command in the [tt]do/done[/tt] loop.

 
Ok..... I'm doing something different.....

The following aliases work ::--->
Code:
alias cscnb01='ssh -tXC jdespres@cscnb01'
alias cscnb02='ssh -tXC jdespres@cscnb02'
alias etsnb02='ssh -tXC jdespres@etsnb02'
alias etsis24='ssh -qtXC jdespres@etsnb02 "ssh -qtXC etsbk31 \"$@\""ssh -qtXC etsis24 \"$@\"""'
alias uphsnb01='ssh -tXC jdespres@faraday "ssh -t -X -C tukey \"$@\""ssh -t -X -C uphsnb01 \"$@\"""'

I converted them to functions ::--->
Code:
cscnb01  () { ssh -tXC jdespres@cscnb01 "$@"; }
cscnb02  () { ssh -tXC jdespres@cscnb02 "$@"; }
etsnb02  () { ssh -tXC jdespres@etsnb02 "$@"; }
cdcnb02  () { ssh -tXC root@cdcnb02 "$@";}
etsis24  () { ssh -tXC jdespres@etsnb02 "ssh -tXC etsbk31 \"$@\""ssh -tXC etsis24 \"$@\"""; }
uphsnb01 () { ssh -tXC jdespres@faraday "ssh -t -X -C tukey \"$@\""ssh -t -X -C uphsnb01 \"$@\"""; }

All the aliases work great....

The last two functions do not..

I'm trying to throw the functions at the following for loop ::--->
Code:
for server in `[ -f $* ] && cat $* || echo  $*`
do
##### Generate the data.....
${server} "/usr/openv/volmgr/bin/vmoprcmd -devmon ds -no_format" 2>/dev/null > /home/pubuntu/${server}_drivestatus.txt 
${server} "/usr/openv/volmgr/bin/vmoprcmd -devmon hs" 2>/dev/null > /home/pubuntu/${server}_hoststatus.txt 
##### Now send out the data.....
echo " "
echo "########## ${server} ##########"
echo " "
/bin/sed '1,4d' /home/pubuntu/${server}_hoststatus.txt| grep -iv connection
echo " "
/usr/bin/awk '{print $6, $3, $7, $8, $10, $36}' /home/pubuntu/${server}_drivestatus.txt |awk '{ if (NF > 5) print}'| sort
echo " "
done

command line ::--->
Code:
script_name (either one server name or a file with names)

Looks like I'm having a issue running the vmoprcmd command across 3 hops...

Basically I'm attempting to run a command on remote systems


Thanks...

Joe Despres
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top