[Glass] run topaz from bash and have access to arguments from topaz smalltalk

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Glass] run topaz from bash and have access to arguments from topaz smalltalk

Mariano Martinez Peck
Hi guys,

In Norbert's utilize, we have this nice script runTopazScript.sh :

#!/bin/sh

source $APPLICATION_DIR/env

if [ -z \$1 ];
then
   echo "no script name given"
fi

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 


That let us automatically connect to GemStone using an auto-generated .topazini. So we can pass around a topaz script and that would be execute. So we can do for example:

sudo sh ./runTopazScript.sh something.tpz 

Now....I saw in several topaz scripts from seaside that the SMALLTALK code is able to directly access the argument variables to the shell. For example, startSeaside30_adaptor does:

GsFile gciLogServer: '$1 Server started on port ', $2 printString.

I want to do the same in my something.tpz. Imagine I have this something.tpz file:

run 
$1 printString.
%

And I execute:

sudo sh ./runTopazScript.sh something.tpz mariano

So how can we adapt the script so that such a smalltalk script outputs 'mariano' instead of the literal string $1 ?

I tried adding a  & at the end of the topaz call and many other workarounds but I am not sure if topaz needs something special for this. 


Thanks a lot in advance and sorry for the offtopic. 

--
Mariano
http://marianopeck.wordpress.com

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] run topaz from bash and have access to arguments from topaz smalltalk

Ralph Mauersberger
Hi Mariano,

to access the arguments from inside topaz you can use a feature of most unix shells called "here document". This concept allows you to embed a document inside your shell script which gets passed to stdin of any executable:

executable <<LimitString
firstCommand
nextCommand $1
LimitString

The document is surrounded by any given string. The shell itself will substitute the environment variables and replace them by there values before the document is passed to the executable.

So use something like the following:

#!/bin/bash

if [ -z \$1 ];
then
   echo "argument expected"
fi

topaz -l <<EOF
set gems $STONENAME user Username pass TopSecret
login
printIt
'$1' printString
%
exit
EOF


You used "run" inside your script which is a normal "do-it". I replaced it by "printIt" because I assume that you are interessted in the evaluated expression.

Topaz has a directive called input. Use that to load other code or if you don't like the login credentials hardcoded in the script:
input $MYAPP_CONFIG/mylogin.topaz

Hope that helps.

Br,
Ralph
 


Am 13.01.2014 15:31, schrieb Mariano Martinez Peck:
Hi guys,

In Norbert's utilize, we have this nice script runTopazScript.sh :

#!/bin/sh

source $APPLICATION_DIR/env

if [ -z \$1 ];
then
   echo "no script name given"
fi

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 


That let us automatically connect to GemStone using an auto-generated .topazini. So we can pass around a topaz script and that would be execute. So we can do for example:

sudo sh ./runTopazScript.sh something.tpz 

Now....I saw in several topaz scripts from seaside that the SMALLTALK code is able to directly access the argument variables to the shell. For example, startSeaside30_adaptor does:

GsFile gciLogServer: '$1 Server started on port ', $2 printString.

I want to do the same in my something.tpz. Imagine I have this something.tpz file:

run 
$1 printString.
%

And I execute:

sudo sh ./runTopazScript.sh something.tpz mariano

So how can we adapt the script so that such a smalltalk script outputs 'mariano' instead of the literal string $1 ?

I tried adding a  & at the end of the topaz call and many other workarounds but I am not sure if topaz needs something special for this. 


Thanks a lot in advance and sorry for the offtopic. 

--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] run topaz from bash and have access to arguments from topaz smalltalk

Mariano Martinez Peck



On Tue, Jan 14, 2014 at 4:27 AM, Ralph Mauersberger <[hidden email]> wrote:
Hi Mariano,

to access the arguments from inside topaz you can use a feature of most unix shells called "here document". This concept allows you to embed a document inside your shell script which gets passed to stdin of any executable:

executable <<LimitString
firstCommand
nextCommand $1
LimitString

The document is surrounded by any given string. The shell itself will substitute the environment variables and replace them by there values before the document is passed to the executable.


Hi Ralph, thanks for the explanation. So indeed, it seems that is what is being used by startSeaside30_adaptor which does:


cat << EOF | nohup $GEMSTONE/bin/topaz -l -e $4 2>&1 >> $GEMSTONE_LOGDIR/${1}_server-${2}.log &


 
So use something like the following:

#!/bin/bash

if [ -z \$1 ];
then
   echo "argument expected"
fi

topaz -l <<EOF
set gems $STONENAME user Username pass TopSecret
login
printIt
'$1' printString
%
exit
EOF


OK, that worked and gets what I want. But....I am unable to apply the same "Here Document" approach to my real needs:

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 

Notice that $1 is the topaz script I send as an argument (yes, it can have a EOF at the end). Also, I am executing topaz with a "su -m -c ..." so that changes the things I guess.

Do you know how can I adapt the above line to use the Here Document features? I would like to access the arguments inside the topaz script sent as argument ($1 in this case). 
 

You used "run" inside your script which is a normal "do-it". I replaced it by "printIt" because I assume that you are interessted in the evaluated expression.


yes, thanks :)
 
Topaz has a directive called input. Use that to load other code or if you don't like the login credentials hardcoded in the script:
input $MYAPP_CONFIG/mylogin.topaz


mmm good idea. 

So...to conclude:

/opt/gemstone/product/bin/topaz -ql -T200000 <<EOF
login
printIt
'$1' printString
%
exit
EOF

that works. But if I do exactly the same but in the file passed as argument, it does not work anymore:

/opt/gemstone/product/bin/topaz -ql -T200000 <<EOF
input $1
EOF


Any ideas?

Thank!





Hope that helps.

Br,
Ralph
 


Am 13.01.2014 15:31, schrieb Mariano Martinez Peck:
Hi guys,

In Norbert's utilize, we have this nice script runTopazScript.sh :

#!/bin/sh

source $APPLICATION_DIR/env

if [ -z \$1 ];
then
   echo "no script name given"
fi

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 


That let us automatically connect to GemStone using an auto-generated .topazini. So we can pass around a topaz script and that would be execute. So we can do for example:

sudo sh ./runTopazScript.sh something.tpz 

Now....I saw in several topaz scripts from seaside that the SMALLTALK code is able to directly access the argument variables to the shell. For example, startSeaside30_adaptor does:

GsFile gciLogServer: '$1 Server started on port ', $2 printString.

I want to do the same in my something.tpz. Imagine I have this something.tpz file:

run 
$1 printString.
%

And I execute:

sudo sh ./runTopazScript.sh something.tpz mariano

So how can we adapt the script so that such a smalltalk script outputs 'mariano' instead of the literal string $1 ?

I tried adding a  & at the end of the topaz call and many other workarounds but I am not sure if topaz needs something special for this. 


Thanks a lot in advance and sorry for the offtopic. 

--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] run topaz from bash and have access to arguments from topaz smalltalk

Ralph Mauersberger
Mariano Martinez Peck schrieb:



On Tue, Jan 14, 2014 at 4:27 AM, Ralph Mauersberger <[hidden email]> wrote:
Hi Mariano,

to access the arguments from inside topaz you can use a feature of most unix shells called "here document". This concept allows you to embed a document inside your shell script which gets passed to stdin of any executable:

executable <<LimitString
firstCommand
nextCommand $1
LimitString

The document is surrounded by any given string. The shell itself will substitute the environment variables and replace them by there values before the document is passed to the executable.


Hi Ralph, thanks for the explanation. So indeed, it seems that is what is being used by startSeaside30_adaptor which does:


cat << EOF | nohup $GEMSTONE/bin/topaz -l -e $4 2>&1 >> $GEMSTONE_LOGDIR/${1}_server-${2}.log &


 
So use something like the following:

#!/bin/bash

if [ -z \$1 ];
then
   echo "argument expected"
fi

topaz -l <<EOF
set gems $STONENAME user Username pass TopSecret
login
printIt
'$1' printString
%
exit
EOF


OK, that worked and gets what I want. But....I am unable to apply the same "Here Document" approach to my real needs:

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 

Notice that $1 is the topaz script I send as an argument (yes, it can have a EOF at the end). Also, I am executing topaz with a "su -m -c ..." so that changes the things I guess.

Do you know how can I adapt the above line to use the Here Document features? I would like to access the arguments inside the topaz script sent as argument ($1 in this case). 
 

You used "run" inside your script which is a normal "do-it". I replaced it by "printIt" because I assume that you are interessted in the evaluated expression.


yes, thanks :)
 
Topaz has a directive called input. Use that to load other code or if you don't like the login credentials hardcoded in the script:
input $MYAPP_CONFIG/mylogin.topaz


mmm good idea. 

So...to conclude:

/opt/gemstone/product/bin/topaz -ql -T200000 <<EOF
login
printIt
'$1' printString
%
exit
EOF

that works. But if I do exactly the same but in the file passed as argument, it does not work anymore:

/opt/gemstone/product/bin/topaz -ql -T200000 <<EOF
input $1
EOF


Mariano,

that should be correct and it works for me. I tested with the following two scripts:

test.sh with the following lines:

#!/bin/bash
topaz -ql <<EOF
input $1
EOF


and input.topaz like this:

set gems seaside user DataCurator pass swordfish
login
printIt
20 factorial
%

I can execute "bash test.sh input.topaz" and get the result.


Just as addition and independent of the here documents approach: Another way to access the shell script arguments would be to export them to the environment and access them via System>>gemEnvironmentVariable:. So the following should also work:

#!/bin/bash
export MYARG=$1
topaz -l <<EOF
set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System gemEnvironmentVariable: 'MYARG')
%
exit
EOF

The here document is just to make the example complete. This way you can access the env vars from within any method.

Br,
Ralph


Any ideas?

Thank!





Hope that helps.

Br,
Ralph
 


Am 13.01.2014 15:31, schrieb Mariano Martinez Peck:
Hi guys,

In Norbert's utilize, we have this nice script runTopazScript.sh :

#!/bin/sh

source $APPLICATION_DIR/env

if [ -z \$1 ];
then
   echo "no script name given"
fi

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 


That let us automatically connect to GemStone using an auto-generated .topazini. So we can pass around a topaz script and that would be execute. So we can do for example:

sudo sh ./runTopazScript.sh something.tpz 

Now....I saw in several topaz scripts from seaside that the SMALLTALK code is able to directly access the argument variables to the shell. For example, startSeaside30_adaptor does:

GsFile gciLogServer: '$1 Server started on port ', $2 printString.

I want to do the same in my something.tpz. Imagine I have this something.tpz file:

run 
$1 printString.
%

And I execute:

sudo sh ./runTopazScript.sh something.tpz mariano

So how can we adapt the script so that such a smalltalk script outputs 'mariano' instead of the literal string $1 ?

I tried adding a  & at the end of the topaz call and many other workarounds but I am not sure if topaz needs something special for this. 


Thanks a lot in advance and sorry for the offtopic. 

--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
      


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] run topaz from bash and have access to arguments from topaz smalltalk

Mariano Martinez Peck


Mariano,

that should be correct and it works for me. I tested with the following two scripts:

test.sh with the following lines:

#!/bin/bash
topaz -ql <<EOF
input $1
EOF


and input.topaz like this:

set gems seaside user DataCurator pass swordfish
login
printIt
20 factorial
%

I can execute "bash test.sh input.topaz" and get the result.


OK, that works for me. But...is there a way I can for example, get something like this: I would like to access the parameters from input.topaz script. For example:

set gems seaside user DataCurator pass swordfish
login
printIt
$2 factorial
%

And then call it like this:

 "bash test.sh input.topaz 20"

I would like to do that without having to export each variable individually...  maybe using $@ somewhere?
 


Just as addition and independent of the here documents approach: Another way to access the shell script arguments would be to export them to the environment and access them via System>>gemEnvironmentVariable:. So the following should also work:

#!/bin/bash
export MYARG=$1
topaz -l <<EOF
set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System gemEnvironmentVariable: 'MYARG')
%
exit
EOF


Ok,  (System gemEnvironmentVariable: 'MYARG') is answering nil ... however.....System performOnServer: 'echo $MYARG'  does answer correctly. 
weird...

 
The here document is just to make the example complete. This way you can access the env vars from within any method.


Thanks!!

 
Br,
Ralph



Any ideas?

Thank!





Hope that helps.

Br,
Ralph
 


Am 13.01.2014 15:31, schrieb Mariano Martinez Peck:
Hi guys,

In Norbert's utilize, we have this nice script runTopazScript.sh :

#!/bin/sh

source $APPLICATION_DIR/env

if [ -z \$1 ];
then
   echo "no script name given"
fi

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 


That let us automatically connect to GemStone using an auto-generated .topazini. So we can pass around a topaz script and that would be execute. So we can do for example:

sudo sh ./runTopazScript.sh something.tpz 

Now....I saw in several topaz scripts from seaside that the SMALLTALK code is able to directly access the argument variables to the shell. For example, startSeaside30_adaptor does:

GsFile gciLogServer: '$1 Server started on port ', $2 printString.

I want to do the same in my something.tpz. Imagine I have this something.tpz file:

run 
$1 printString.
%

And I execute:

sudo sh ./runTopazScript.sh something.tpz mariano

So how can we adapt the script so that such a smalltalk script outputs 'mariano' instead of the literal string $1 ?

I tried adding a  & at the end of the topaz call and many other workarounds but I am not sure if topaz needs something special for this. 


Thanks a lot in advance and sorry for the offtopic. 

--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
      


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] run topaz from bash and have access to arguments from topaz smalltalk

Mariano Martinez Peck



On Tue, Jan 14, 2014 at 1:01 PM, Mariano Martinez Peck <[hidden email]> wrote:


Mariano,

that should be correct and it works for me. I tested with the following two scripts:

test.sh with the following lines:

#!/bin/bash
topaz -ql <<EOF
input $1
EOF


and input.topaz like this:

set gems seaside user DataCurator pass swordfish
login
printIt
20 factorial
%

I can execute "bash test.sh input.topaz" and get the result.


OK, that works for me. But...is there a way I can for example, get something like this: I would like to access the parameters from input.topaz script. For example:

set gems seaside user DataCurator pass swordfish
login
printIt
$2 factorial
%

And then call it like this:

 "bash test.sh input.topaz 20"

I would like to do that without having to export each variable individually...  maybe using $@ somewhere?
 


I forgot to said....somehow that works for startSeaside30_Adaptor.... but I don't understand how it can do it. 


 


Just as addition and independent of the here documents approach: Another way to access the shell script arguments would be to export them to the environment and access them via System>>gemEnvironmentVariable:. So the following should also work:

#!/bin/bash
export MYARG=$1
topaz -l <<EOF
set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System gemEnvironmentVariable: 'MYARG')
%
exit
EOF


Ok,  (System gemEnvironmentVariable: 'MYARG') is answering nil ... however.....System performOnServer: 'echo $MYARG'  does answer correctly. 
weird...

 
The here document is just to make the example complete. This way you can access the env vars from within any method.


Thanks!!

 
Br,
Ralph



Any ideas?

Thank!





Hope that helps.

Br,
Ralph
 


Am 13.01.2014 15:31, schrieb Mariano Martinez Peck:
Hi guys,

In Norbert's utilize, we have this nice script runTopazScript.sh :

#!/bin/sh

source $APPLICATION_DIR/env

if [ -z \$1 ];
then
   echo "no script name given"
fi

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 


That let us automatically connect to GemStone using an auto-generated .topazini. So we can pass around a topaz script and that would be execute. So we can do for example:

sudo sh ./runTopazScript.sh something.tpz 

Now....I saw in several topaz scripts from seaside that the SMALLTALK code is able to directly access the argument variables to the shell. For example, startSeaside30_adaptor does:

GsFile gciLogServer: '$1 Server started on port ', $2 printString.

I want to do the same in my something.tpz. Imagine I have this something.tpz file:

run 
$1 printString.
%

And I execute:

sudo sh ./runTopazScript.sh something.tpz mariano

So how can we adapt the script so that such a smalltalk script outputs 'mariano' instead of the literal string $1 ?

I tried adding a  & at the end of the topaz call and many other workarounds but I am not sure if topaz needs something special for this. 


Thanks a lot in advance and sorry for the offtopic. 

--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
      


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com



--
Mariano
http://marianopeck.wordpress.com

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] run topaz from bash and have access to arguments from topaz smalltalk

Ralph Mauersberger
Mariano Martinez Peck schrieb:



On Tue, Jan 14, 2014 at 1:01 PM, Mariano Martinez Peck <[hidden email]> wrote:


Mariano,

that should be correct and it works for me. I tested with the following two scripts:

test.sh with the following lines:

#!/bin/bash
topaz -ql <<EOF
input $1
EOF


and input.topaz like this:

set gems seaside user DataCurator pass swordfish
login
printIt
20 factorial
%

I can execute "bash test.sh input.topaz" and get the result.


OK, that works for me. But...is there a way I can for example, get something like this: I would like to access the parameters from input.topaz script. For example:

set gems seaside user DataCurator pass swordfish
login
printIt
$2 factorial
%

And then call it like this:

 "bash test.sh input.topaz 20"

I would like to do that without having to export each variable individually...  maybe using $@ somewhere?
 
Hmm, I don't think that there is a way to get something like that directly working. Of course there are workarounds, like storing $2 to a file, save it to sessionState or whatever and afterwards access it from within input.topaz with appropriate smalltalk code.


I forgot to said....somehow that works for startSeaside30_Adaptor.... but I don't understand how it can do it.
Maybe I'm blind, but I can't see any special trick in startSeaside30_Adaptor. It's just one here document passed to "cat", the result is piped to topaz. $1 and $2 are used inside the here document and are substituted by the shell like we discussed it. $1 and $2 are also used to specify the log file name.



 


Just as addition and independent of the here documents approach: Another way to access the shell script arguments would be to export them to the environment and access them via System>>gemEnvironmentVariable:. So the following should also work:

#!/bin/bash
export MYARG=$1
topaz -l <<EOF
set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System gemEnvironmentVariable: 'MYARG')
%
exit
EOF


Ok,  (System gemEnvironmentVariable: 'MYARG') is answering nil ... however.....System performOnServer: 'echo $MYARG'  does answer correctly. 
weird...

 
The here document is just to make the example complete. This way you can access the env vars from within any method.


Thanks!!

 
Br,
Ralph



Any ideas?

Thank!





Hope that helps.

Br,
Ralph
 


Am 13.01.2014 15:31, schrieb Mariano Martinez Peck:
Hi guys,

In Norbert's utilize, we have this nice script runTopazScript.sh :

#!/bin/sh

source $APPLICATION_DIR/env

if [ -z \$1 ];
then
   echo "no script name given"
fi

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 


That let us automatically connect to GemStone using an auto-generated .topazini. So we can pass around a topaz script and that would be execute. So we can do for example:

sudo sh ./runTopazScript.sh something.tpz 

Now....I saw in several topaz scripts from seaside that the SMALLTALK code is able to directly access the argument variables to the shell. For example, startSeaside30_adaptor does:

GsFile gciLogServer: '$1 Server started on port ', $2 printString.

I want to do the same in my something.tpz. Imagine I have this something.tpz file:

run 
$1 printString.
%

And I execute:

sudo sh ./runTopazScript.sh something.tpz mariano

So how can we adapt the script so that such a smalltalk script outputs 'mariano' instead of the literal string $1 ?

I tried adding a  & at the end of the topaz call and many other workarounds but I am not sure if topaz needs something special for this. 


Thanks a lot in advance and sorry for the offtopic. 

--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
      


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com



--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] run topaz from bash and have access to arguments from topaz smalltalk

Mariano Martinez Peck



On Tue, Jan 14, 2014 at 1:43 PM, Ralph Mauersberger <[hidden email]> wrote:
Mariano Martinez Peck schrieb:



On Tue, Jan 14, 2014 at 1:01 PM, Mariano Martinez Peck <[hidden email]> wrote:


Mariano,

that should be correct and it works for me. I tested with the following two scripts:

test.sh with the following lines:

#!/bin/bash
topaz -ql <<EOF
input $1
EOF


and input.topaz like this:

set gems seaside user DataCurator pass swordfish
login
printIt
20 factorial
%

I can execute "bash test.sh input.topaz" and get the result.


OK, that works for me. But...is there a way I can for example, get something like this: I would like to access the parameters from input.topaz script. For example:

set gems seaside user DataCurator pass swordfish
login
printIt
$2 factorial
%

And then call it like this:

 "bash test.sh input.topaz 20"

I would like to do that without having to export each variable individually...  maybe using $@ somewhere?
 
Hmm, I don't think that there is a way to get something like that directly working. Of course there are workarounds, like storing $2 to a file, save it to sessionState or whatever and afterwards access it from within input.topaz with appropriate smalltalk code.


OK.... I got it.  But just to confirm... this works:


#!/bin/bash
export MYARG=$1
topaz -l <<EOF
set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System performOnServer: 'echo $MYARG').
%
login
printIt
'$1' printString
%
exit
EOF 

and run it "sh runTopaz.sh mariano"

but if we move the topaz script to a separate file and we do the input...it doesn't work anymore:

#!/bin/bash
export MYARG=$1
topaz -l <<EOF
input test.tpz
EOF 

"sh runTopaz.sh mariano"

and test.tpz being:

set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System performOnServer: 'echo $MYARG').
%
login
printIt
'$1' printString
%
exit

so the only way to get it work is to embed the topaz script inside the bash script right? (like the first example)

Ok...if I embed the topaz script in the bash (not using input) I can access both, parameters and exported variables, from both, topaz and smalltalk. 
If I don't embed the topaz script (use input), then, I cannot access any variable either from topaz or smalltalk.

so...this is the expected behavior right? 
 
I forgot to said....somehow that works for startSeaside30_Adaptor.... but I don't understand how it can do it.
Maybe I'm blind, but I can't see any special trick in startSeaside30_Adaptor. It's just one here document passed to "cat", the result is piped to topaz. $1 and $2 are used inside the here document and are substituted by the shell like we discussed it. $1 and $2 are also used to specify the log file name.


You right, I missed that difference. You right, it's not the same case. 


Thanks a lot Ralph for your help, it is really appreciated. 
 


 


Just as addition and independent of the here documents approach: Another way to access the shell script arguments would be to export them to the environment and access them via System>>gemEnvironmentVariable:. So the following should also work:

#!/bin/bash
export MYARG=$1
topaz -l <<EOF
set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System gemEnvironmentVariable: 'MYARG')
%
exit
EOF


Ok,  (System gemEnvironmentVariable: 'MYARG') is answering nil ... however.....System performOnServer: 'echo $MYARG'  does answer correctly. 
weird...

 
The here document is just to make the example complete. This way you can access the env vars from within any method.


Thanks!!

 
Br,
Ralph



Any ideas?

Thank!





Hope that helps.

Br,
Ralph
 


Am 13.01.2014 15:31, schrieb Mariano Martinez Peck:
Hi guys,

In Norbert's utilize, we have this nice script runTopazScript.sh :

#!/bin/sh

source $APPLICATION_DIR/env

if [ -z \$1 ];
then
   echo "no script name given"
fi

cat ../scripts/login.st \$1 | su -m $GEMSTONE_USER -c \"$GEMSTONE/bin/topaz -ql -T200000 \" 


That let us automatically connect to GemStone using an auto-generated .topazini. So we can pass around a topaz script and that would be execute. So we can do for example:

sudo sh ./runTopazScript.sh something.tpz 

Now....I saw in several topaz scripts from seaside that the SMALLTALK code is able to directly access the argument variables to the shell. For example, startSeaside30_adaptor does:

GsFile gciLogServer: '$1 Server started on port ', $2 printString.

I want to do the same in my something.tpz. Imagine I have this something.tpz file:

run 
$1 printString.
%

And I execute:

sudo sh ./runTopazScript.sh something.tpz mariano

So how can we adapt the script so that such a smalltalk script outputs 'mariano' instead of the literal string $1 ?

I tried adding a  & at the end of the topaz call and many other workarounds but I am not sure if topaz needs something special for this. 


Thanks a lot in advance and sorry for the offtopic. 

--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
      


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com



--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--
Mariano
http://marianopeck.wordpress.com

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] run topaz from bash and have access to arguments from topaz smalltalk

Richard Sargent
Administrator
In reply to this post by Mariano Martinez Peck
I have created a bug related to this, to allow Smalltalk to access the command line arguments (i.e., argv) that were used to launch the Gem.

43659: 'Add the ability to get the command arguments used to launch the gem'

This means that the Topaz session will have access to them, but only within the Smalltalk portion of the system. Since that's where we all want to play anyway, it should be good. :-)


It looks like it will make it into 3.2.
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] run topaz from bash and have access to arguments from topaz smalltalk

Ralph Mauersberger
In reply to this post by Mariano Martinez Peck


Just as addition and independent of the here documents approach: Another way to access the shell script arguments would be to export them to the environment and access them via System>>gemEnvironmentVariable:. So the following should also work:

#!/bin/bash
export MYARG=$1
topaz -l <<EOF
set gems seaside user DataCurator pass swordfish
login
printIt
'The first argument was: ', (System gemEnvironmentVariable: 'MYARG')
%
exit
EOF


Ok,  (System gemEnvironmentVariable: 'MYARG') is answering nil ... however.....System performOnServer: 'echo $MYARG'  does answer correctly. 
weird...

Hmm, really strange. I have no idea. The example above works as expected for me. I tested on a non-GLASS GemStone/S 64 2.4.4.7 (SPARC Solaris). So maybe a bug in a recent GS 3.x or whatever version you are using?

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass