This bash resource needs to run via oracle user…
how to modify the code to switch user.
this is the method i am using but i need some other option to do so such that complete resource gets executed as oracle user.
#logs for space and memory availability
bash ‘xxxx’ do
cwd aaaa
code <<-EOH
su - oracle -c "sqlplus -v > /oracle/local/log/softwareversion.txt"
su - oracle -c "df -h > /oracle/local/log/serverspace.txt"
su - oracle -c "free -g > /oracle/local/log/memoryspace.txt"
EOH
end
When the recipe runs on node it shows some error like this
bash[xxxxx] action run
[execute] stty: standard input: Invalid argument
stty: standard input: Invalid argument
stty: standard input: Invalid argument
stty: standard input: Invalid argument
stty: standard input: Invalid argument
bash 'name' do
code String
creates String
cwd String
environment Hash
flags String
group String, Integer
notifies # see description
path Array
provider Chef::Provider::Script::Bash
returns Integer, Array
subscribes # see description
timeout Integer, Float
user String, Integer
umask String, Integer
action Symbol # defaults to :run if not specified
end
where i am using execute resource… i have used su - oracle for that
but with bash i am writing su - oracle for each and every command inside bash resource as mentioned above
code <<-EOH
su - oracle -c "sqlplus -v > /oracle/local/log/softwareversion.txt"
su - oracle -c "df -h > /oracle/local/log/serverspace.txt"
su - oracle -c "free -g > /oracle/local/log/memoryspace.txt"
EOH
and can you tell how can i remove this error
stty: standard input: Invalid argument
stty: standard input: Invalid argument
stty: standard input: Invalid argument
stty: standard input: Invalid argument
#logs for space and memory availability
base = node[‘testcookbook’][‘ora_base’]
bash ‘check_space’ do
code <<-EOH
echo $USER > /tmp/env.lst
EOH
user 'oracle’
group 'dba’
end
Now this should give user as oracle but the result is root which means that user property of bash resource is not moving to oracle.
is it a bug??
because instead of using this if we use su - oracle -c “command” then it works fine
That “echo $user” command is not really proof of which user is running - it simply takes whatever is stored in the environment variable. I would assume that the bash resource inherits the environment from the chef run (much akin to what happens when you use “su oracle” rather than “su - oracle”).
If you really want to test, do this:
bash ‘test_root’ do
code <<-EOH
cat /root/.bashrc >/tmp/env.lst
EOH
user 'oracle’
group 'dba’
end
You should get a permission denied if this runs as user oracle, or success if it runs as user root.