Hey all, I was wondering if someone would take a look at this script I'm working on. I don't know if i have the syntax correct for my variables and if the for loop is written correctly.
any assistance would be greatly appreciated.
#!/usr/bin/bash
###########################################
# Written By: em
# Purpose: This script was written to make changes to a basic zone setup
# Date: 01 July 2008
###########################################
# My Variables
DMI_FILE="/etc/dmi/conf"
SNMP_FILE="/etc/snmp/conf"
##########
# Code
##########
if [[ -e $DMI_FILE ]]; then #check to see if the file exists
for conf in $($DMI_FILE)
do
mv conf conf.orig
done
else
print "$DMI_FILE does not exist"
exit
fi
echo "/etc/dmi/conf has been moved"
if [[ -e $SNMP_FILE ]]; then #check to see if the file exists
for conf in $($SNMP_FILE)
do
mv conf conf.orig
done
else
print "$SNMP_FILE does not exist"
exit
fi
#!/usr/bin/ksh
if [ -e /etc/dmi/conf/ ]; then #check to see if /etc/dmi/conf exists
mv conf conf.orig # move the file to .orig
else
print "/etc/dmi/conf does not exist"
fi
if [ -e /etc/snmp/conf/ ]; then # check to see if /etc/snmp/conf exists
mv conf conf.orig # move the conf to .orig
else
print "/etc/snmp/conf does not exist"
fi
Is the start of the script trying to rename both the files named in shell variables ${DMI_FILE} and ${SNMP_FILE} , rather than a file called "conf" in the current working directory ?
If so, then please try the construct below (untested) and remove the "echo" from the "mv" line if it does what you want. I've avoided having a shell variable called "conf" because it appears to be causing confusion! Where you had a shell variable called "conf" I have called it "filename". We are back to "bash" because I don't think that "test -e" is valid in ksh.
#!/usr/bin/bash
# My Variables
DMI_FILE="/etc/dmi/conf"
SNMP_FILE="/etc/snmp/conf"
for filename in "${DMI_FILE}" "${SNMP_FILE}"
do
if [ -e "${filename}" ]
then
echo mv "${filename}" "${filename}.orig"
echo "${filename} has been moved"
else
echo "${filename} does not exist"
exit
fi
done
actually, conf is a directory and i'm trying to move said directory (conf) to conf.orig which works just fine if i do mv /etc/dmi/conf /etc/dmi/conf.orig. but i'm working with multiple zones in solaris, and every setup I do I have a list of basic steps, which i'm trying to throw into a script.