-
How to run an awk '{print $2}' inside a su - <user> ' comands ...'
Hi,
I'm trying to do a shell script that needs to run several commands
with different user rights.
I'm having problems when I want to do this:
SEMBLOQ=`ipcs -s | grep mqm | awk '{print $2}'`
su - mqm '
for i in $SEMBLOQ; do
echo "Parando el semaforo con PID " $i;
ipcrm -s $i;
done;
'
Because inside the su -mqm ' ....' command the variable $SEMBLOQ
doesn't exist,
I've also tried to put the variable definition inside but It neither
works, I think the problem now it's that ' ...' of su and ' ....' of
awk are not distinguished
Anyone knows who to solve it.
Thanks
Juanjo
-
Re: How to run an awk '{print $2}' inside a su - <user> ' comands...'
The export command will make a variable visible to child processes:
juanjo.83@gmail.com wrote:
> SEMBLOQ=`ipcs -s | grep mqm | awk '{print $2}'`
export SEMBLOQ
>
> su - mqm '
> for i in $SEMBLOQ; do
> echo "Parando el semaforo con PID " $i;
> ipcrm -s $i;
> done;
> '
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GE d+(-) s+: a@ C+ ULAHS++$ P- L+>++ E--- W++ N++ o !K w--(+) O- M?>+ V? PS+
PE+(++) Y+ PGP- t+ 5 X R !tv b+ DI(+) D G e++ h---- r+++@ y++++
------END GEEK CODE BLOCK------
-
Re: How to run an awk '{print $2}' inside a su - <user> ' comands ...'
Thank you, I've tried it but doesn't work.
BTW, I'm writing in ksh on Solaris 9.
On 15 mayo, 12:40, SiKing wrote:
> The export command will make a variable visible to child processes:
>
> juanjo...@gmail.com wrote:
> > SEMBLOQ=`ipcs -s | grep mqm | awk '{print $2}'`
>
> export SEMBLOQ
>
>
>
> > su - mqm '
> > for i in $SEMBLOQ; do
> > echo "Parando el semaforo con PID " $i;
> > ipcrm -s $i;
> > done;
> > '
>
> --
> -----BEGIN GEEK CODE BLOCK-----
> Version: 3.1
> GE d+(-) s+: a@ C+ ULAHS++$ P- L+>++ E--- W++ N++ o !K w--(+) O- M?>+ V? PS+
> PE+(++) Y+ PGP- t+ 5 X R !tv b+ DI(+) D G e++ h---- r+++@ y++++
> ------END GEEK CODE BLOCK------
-
Re: How to run an awk '{print $2}' inside a su - <user> ' comands ...'
On May 15, 4:00 am, juanjo...@gmail.com wrote:
> Thank you, I've tried it but doesn't work.
>
> BTW, I'm writing in ksh on Solaris 9.
>
> On 15 mayo, 12:40, SiKing wrote:
>
>
>
> > The export command will make a variable visible to child processes:
>
> > juanjo...@gmail.com wrote:
> > > SEMBLOQ=`ipcs -s | grep mqm | awk '{print $2}'`
>
> > export SEMBLOQ
>
> > > su - mqm '
> > > for i in $SEMBLOQ; do
> > > echo "Parando el semaforo con PID " $i;
> > > ipcrm -s $i;
> > > done;
> > > '
As long as your ipcs command does not require root to execute,
try moving this line:
SEMBLOQ=`ipcs -s | grep mqm | awk '{print $2}'`
inside the quotes for your command after your 'su - mqm'
(you'll need to change how you quote some things)
i.e. execute this after you su and before your for loop
-
Re: How to run an awk '{print $2}' inside a su - <user> ' comands...'
juanjo.83@gmail.com a écrit :
> Hi,
>
> I'm trying to do a shell script that needs to run several commands
> with different user rights.
>
> I'm having problems when I want to do this:
>
>
> SEMBLOQ=`ipcs -s | grep mqm | awk '{print $2}'`
>
> su - mqm '
> for i in $SEMBLOQ; do
> echo "Parando el semaforo con PID " $i;
> ipcrm -s $i;
> done;
> '
>
> Because inside the su -mqm ' ....' command the variable $SEMBLOQ
> doesn't exist,
>
> I've also tried to put the variable definition inside but It neither
> works, I think the problem now it's that ' ...' of su and ' ....' of
> awk are not distinguished
>
>
> Anyone knows who to solve it.
>
> Thanks
> Juanjo
>
The "su" block must define your SEMBLOQ variable
su - mqm '
SEMBLOQ=`ipcs -s | grep mqm | awk '{print $2}'
for i in $SEMBLOQ; do
echo "Parando el semaforo con PID " $i;
ipcrm -s $i;
done;
'
YW
Stephane
-
Re: How to run an awk '{print $2}' inside a su - <user> ' comands ...'
2007-05-15, 01:42(-07), juanjo.83@gmail.com:
> Hi,
>
> I'm trying to do a shell script that needs to run several commands
> with different user rights.
>
> I'm having problems when I want to do this:
>
>
> SEMBLOQ=`ipcs -s | grep mqm | awk '{print $2}'`
>
> su - mqm '
> for i in $SEMBLOQ; do
> echo "Parando el semaforo con PID " $i;
> ipcrm -s $i;
> done;
> '
>
> Because inside the su -mqm ' ....' command the variable $SEMBLOQ
> doesn't exist,
>
> I've also tried to put the variable definition inside but It neither
> works, I think the problem now it's that ' ...' of su and ' ....' of
> awk are not distinguished
[...]
On which system does su have such a syntax?
Why not simply
SEMBLOQ=$(ipcs -s | awk '$3 == "mam" {printf "%s ", $2}')
su mqm -c "ipcrm sem $SEMBLOQ"
(if on Linux)
Or:
ipcs -s |
awk '$3 == "mqm" {print "ipcrm -s", $2}' |
su mqm
--
Stéphane