Sourcing a file in a script
Hi all,
So I have a short bash script written with the goal of being able to download a zip folder containing credentials for a software program, unzip them and source them. Unfortunately the sourcing is not taking place, or if it is, it only lasts during the execution of the script and not outside it. Problem is I need it to be effective outside of the script. So, the script looks like so: get-creds.sh #!/bin/bash yum install unzip -y mkdir .creds cd .creds /usr/sbin/euca_conf --get-credentials admin.zip unzip admin.zip source eucarc cd I execute it from the terminal like so: ./folder/folder/folder/get-creds.sh how can I set up the script so that that source command works outside the script as well? The credentials file needs to be sourced to run some commands and I want it as automated as possible. Thanks |
Do the creds change from download to download?
If not, just leave eucarc somewhere (one directory above?) and use source /path/to/eucarc in your ~/.bashrc file. |
basically, you can't
once the bash script exits, its environment is 'lost' However.. instead of using a script, add a function in your ~/.bashrc Code:
get-creds () { then type get-creds Warning: I didn't fix your script
check if you already have unzip Code:
[[ -x $(which unzip) ]] || sudo yum install unzip -y Code:
TempDir=$(mktemp -d) |
Yes the creds will change from download to download.
The script will be run as the initial install, users may need to source the cred file again at a later point manually if they exit the terminal/close the remote session or whatever. Or if for some reason the programs database needs overwritten new credentials will have to be downloaded and sourced. The path however will not change, unless the user messes up and puts it somewhere else in the scenario that they need to be redownloaded. |
Quote:
|
Quote:
|
wow.
|
I shall use my imagination then
Code:
#!/bin/bash Warning: basic script, no real error checks http://www.tldp.org/LDP/Bash-Beginners-Guide/html/ http://www.tldp.org/LDP/abs/html/ http://mywiki.wooledge.org/BashGuide http://www.gnu.org/software/bash/manual/bashref.html |
Yeah that is way over my head lol
thanks |
If you want to make life easy for your clients you will need to learn some scripting
looking back I would change the cat > $SourceFile <<-END Code:
cat > $SourceFile <<-END it should also include an uninstall function, to cleanup the users ~/.bashrc and so on |
All times are GMT -5. The time now is 10:20 AM. |