Quantcast
Channel: A Portal to a Portal
Viewing all articles
Browse latest Browse all 1850

Scripting the shell

$
0
0
One of my friends was looking for a mechanism to invoke a script as another user AND pass in a parameter.

Challenge, accepted :-)

Here's my script: -

/home/db2inst1/foobar.sh 

#!/bin/bash
echo "Hello World! from `whoami`"
echo "And today's special is " $1 "!!! "
exit


and here's how I invoke it from another user ( root ): -

su - db2inst1 -c '/home/db2inst1/foobar.sh Fish'

Hello World! from db2inst1
And today's special is  Fish !!! 

su - db2inst1 -c "/home/db2inst1/foobar.sh Beef"

Hello World! from db2inst1
And today's special is  Beef !!! 


Bottom line, wrap the remote command in single or double quotes, with the parameter passed after the name of the script.

Viewing all articles
Browse latest Browse all 1850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>