I am trying to create a setup type script that will interact with a user to gather data, then populate the /etc/hosts file with the IP address provided.
Code:
#!/bin/bash
# this is a test
CONFFILE="${HOMEDIR}/.nasbackup"
firstTime=0
if [ -f ${HOMEDIR}/.nasbackup ]
then
echo "${CONFFILE} | tee -a ${LOG}
else
echo "Creating ${CONFFILE}" | tee -a ${LOG}
sleep 1
echo -n "active." >${CONFFILE}.tmp
firstTime=1
fi
echo "ftp.rx30backup.com" >>${CONFFILE}.tmp
echo "Running setup for NAS backup with e-mail notificatoin."
echo "Previous configurations will be overwritten."
echo -n "Continue? (Y/N) :"
read ANSWER
if [[ ${ANSWER} != [Yy] ]]
then
exit 1
fi
echo -n "Enter the user name for the NAS device: "
read USER
echo -en "\t${USER}" >>${CONFFILE}.tmp
echo -n "Enter the password for the NAS device: "
read PASS
echo -en "\t${PASS}" >>${CONFFILE}.tmp
echo -n "Enter the IP of the NAS device: "
read IP
echo -en "\t${IP}" >>${CONFFILE}.tmp
echo -n "Enter the path for the backup"\r "ex: disk1/rx30 :"
read RDIR
echo -en "\t${RDIR}" >>${CONFFILE}.tmp
echo "Do you want to configure the backup program to restart"
echo -n "Vrtual Pharmacist after the backup is complete?(Y/N) "
read VP
if [[ ${VP} = [Yy] ]]
then
echo -en "\tVirtRPH" >>${CONFFILE}.tmp
fi
if [ ${firstTime} -eq 1 ]
then
echo "First time setup for NAS. Enter the root password when prompted."
echo -n "Typically this is 1234"
fi
mv ${CONFFILE}.tmp ${CONFFILE}
grep -w "ftp.rx30backup.com" /etc/hosts || { echo "Adding hosts entry" | tee -a ${LOG}
set - `cat ${CONFFILE}`
echo "User name is $2 Password is $3 IP address is $4 Path is $5 5 is $6"
su - -c 'echo "/$4 $1">> /etc/hosts
echo " "
echo "Setup is complete."
echo " "
echo -n "Do you wish to read the help menu? (Y/N) :"
read ANSWER2
if [[ ${ANSWER2} -eq [Yy] ]]
then
USAGE | less
sleep 1
else
echo -n "Do you wish to run a backup now? (Y/N) :"
read ANSWER3
if [[ ${ANSWER3} != [Yy] ]]
then
exit 2
fi
fi
when i manually create the .backup file (just using that as an example) then set - `cat .backup` i can echo out the data i want from the file and it reports exactly as i would expect.
The problem is when I su -
Code:
su - -c 'echo "$4 $1">> /etc/hosts
i am prompted for the root p/w as i would expect, but when i cat /etc/hosts there is nothing there. yet if i:
[code]echo "$4 $1" i am presented with:
Code:
192.168.0.60 ftp.rx30backup.com
why is this NOT being populated into /etc/hosts.
oh and yes i can:
Code:
echo "192.168.0.60 ftp.rx30backup.com >> /etc/hosts
and that works without issue. what am i doing wrong?