PROBLEM:
I am struggling with this cp always giving errors because the variables not there...
Here is my code:
if [ ! -z "$USER1" ]
then
sudo -u "$USER1" bash <<'EOF'
sleep 5
BASHRC=.bashrc
cp "$BASHRC" "$HOME"/.bashrc
sleep 5
wget https://raw.github.com/trapd00r/LS_COLORS/master/LS_COLORS -O "$HOME"/.dircolors
sleep 5
echo 'eval $(dircolors -b $HOME/.dircolors)' >> "$HOME"/.bashrc
. "$HOME"/.bashrc
sleep 5
echo "Here is LS_COLORS in action: "
ls -l "$HOME"
EOF
fi
QUESTIONS:
How to make my script-varibles and environmental variables accessable inside the sudo clauses(there are many)?
Is it sudo or is it here-document that has a problem with this?
EDIT:
Removing the quotes on EOF gives me a previous problem:
./testing3892739.sh billy
cp: failed to access '/root/.bashrc': Permission denied
EDIT2:
Now the script looks like this.....
if [ ! -z "$USER1" ]
108 then
109 sudo -i -u "$USER1" bash <<'EOF'
110 sleep 5
111 cp -f .bashrc "$HOME"/.bashrc
112 sleep 5
113 wget https://raw.github.com/trapd00r/LS_COLORS/master/LS_COLORS -O "$HOME"/.dircolors
114 sleep 5
115 echo 'eval $(dircolors -b $HOME/.dircolors)' >> "$HOME"/.bashrc
116 . "$HOME"/.bashrc
117 sleep 5
118 echo "Here is LS_COLORS in action: "
119 ls -l "$HOME"
120 EOF
121 fi
the -i switch to sudo made the difference on the last problem....
but as usual and for some time now and many different errors, cp gives an error and now it is
cp: '.bashrc' and '/home/billy/.bashrc' are the same file
The file exist's but I need it to be overwritten.
I simply want my script to cp the hidden file .bashrc from current dir which can be anywhere because this is the dir the script resides and files needed for the update of the server, into $HOME and overwrite if it's existing.
$HOMEto expand to$USER1's home directory - to achieve that, you probably need to invoke a login shell by adding-ior--loginto yoursudoinvocation.cp: '.bashrc' and '/home/billy/.bashrc' are the same fileno problem when I do this for root