sudo in bash script grep environment
I am creating a script to stop and start a application.
The script has to do a sudo and then start a script. The path to the script begins with a variable which is set when logging on. This path isn't exported so I can't use the environment variable. I am no trying to grep the variable but it isn't working. I am doing the following Code:
sudo su - user The echo stays empty. Can someone help me with this problem. |
Hello,
Check your spelling of "DIRECTORY" within your echo statement... That might be your problem. Also, you seem to be missing some code... Could you edit your post and make it reflect your original code? Thanks! Cheers, Josh |
Assuming all is well beyond that, I'm dubious whether you can su to another user from within a shell script. You probably get the output of the echo statement until after you exit from the other user's shell. Even if you background the shell, you've still only run the script as your original user.
Could you split this into two scripts? The last two lines of the first could be Code:
D="$( env | grep -i appl)" Code:
D="$*" Code:
man setuid |
The complete script I have is
Code:
ssh SERVER <<HERE Only the directory variable can't be filled |
First of all, "#!/bin/bash" should be at the very top of your script. Second of all, can you verify for me that the command you are trying to store in your variable works? Lastly, after you store data in a variable, the correct way to call it is the following:
Code:
DIRECTORY="$(env | grep -i appl)" |
When I sudo to the user and run the script to get the variable filled it works
When running the script as my own user and having it sudo and then fill the variable isn't working |
So then have you tried using sudo with the command itself?
Code:
DIRECTORY="$(sudo env | grep -i appl)" |
When I try this I get the following reply
Quote:
|
Try sudo with the -u flag and tell it to manually use the root user to execute env. That would be part of the problem, as it is trying to use your normal user. How is your sudo configuration setup, anyway?
|
I still get the same message.
I am not able to view the /etc/sudoers file. But I know it isn't possible to do something like Quote:
|
Why can't you view that file? You are indeed the administrator of the box you are on, correct?
|
Are you certain you can't predict the directory? Why not?
Are you connecting to a Windows box running Cygwin and grepping for "Application Data" or something? Please post the output of Code:
sudo -l |
I am not the administrator off the machine, I am a user (Technical Application Manager)
The output off sudo -l is Quote:
|
There's your problem. You need to get your administrator to give you access, plain and simple.
|
I will contact them.
Thank you for the help. |
All times are GMT -5. The time now is 09:05 AM. |