The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Defining EDITOR Variable - Tru64 Bagel08 UNIX for Dummies Questions & Answers 2 12-15-2008 12:05 PM
defining a printer in qconfig matheeq AIX 0 03-18-2008 11:55 AM
Defining Variables sailorliones UNIX for Dummies Questions & Answers 4 07-21-2006 04:09 PM
defining a variable as a number or character? noobian UNIX for Dummies Questions & Answers 1 04-26-2005 09:19 PM
Defining variables at boot time ianf UNIX for Dummies Questions & Answers 7 01-07-2002 01:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-03-2009
em23's Avatar
em23 em23 is offline
Registered User
  
 

Join Date: May 2008
Location: Chicago
Posts: 31
defining variables

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

echo "/etc/snmp/conf has been moved"


#
# disable services
#
/usr/sbin/svcadm disable svc:/network/finger:default
/usr/sbin/svcadm disable svc:/network/login:rlogin
/usr/sbin/svcadm disable svc:/network/shell:default
/usr/sbin/svcadm disable svc:/network/telnet:default
/usr/sbin/svcadm disable svc:/network/rpc/rstat:default
/usr/sbin/svcadm disable svc:/network/rpc/rusers:default
/usr/sbin/svcadm disable svc:/network/smtp:sendmail
/usr/sbin/svcadm disable svc:/network/ftp:default
/usr/sbin/svcadm disable svc:/system/filesystem/autofs:default

echo "The requested services have been disabled"

#
# disable automounter
#
/usr/bin/svcadm disable autofs

echo "automounter disabled"

#
# edit auto_master
#
vi /etc/auto_master

echo "Basic Zone Setup is complete"
  #2 (permalink)  
Old 01-03-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,378
Quote:
Originally Posted by em23 View Post
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.

Did you run the script? If you did you would have received error messages telling you what and where the errors were.
Quote:
any assistance would be greatly appreciated.

When posting code, please put it in [code] tags.
Quote:

Code:
if [[ -e $DMI_FILE ]]; then #check to see if the file exists

[[ -e ... ]] is not standard and, in this case, offers nothing over the standard [ -e ... ].
Quote:

Code:
    for conf in $($DMI_FILE)

There's an obvious mistake. Why are you using command substitution when the variable does not contain a command?
  #3 (permalink)  
Old 01-03-2009
em23's Avatar
em23 em23 is offline
Registered User
  
 

Join Date: May 2008
Location: Chicago
Posts: 31
Quote:
Originally Posted by cfajohnson View Post

Did you run the script? If you did you would have received error messages telling you what and where the errors were.
i did, but didn't get any errors.

When posting code, please put it in [code] tags.
d'oh! forgot about that.

[[ -e ... ]] is not standard and, in this case, offers nothing over the standard [ -e ... ].
okay, was not aware of that. thank you.

There's an obvious mistake. Why are you using command substitution when the variable does not contain a command?
typo, i forgot the 'ls' in there.
  #4 (permalink)  
Old 01-03-2009
em23's Avatar
em23 em23 is offline
Registered User
  
 

Join Date: May 2008
Location: Chicago
Posts: 31
here is are the changes that i made.



Code:

#!/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

  #5 (permalink)  
Old 01-03-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,378
Quote:
Originally Posted by em23 View Post
here is are the changes that i made.


Code:
#!/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

What are you trying to move? You haven't checked whether there is a file (or directory) called conf in the current directory.
Quote:
Code:
else
   print "/etc/dmi/conf does not exist"

How do you know that /etc/dmi/conf doesn't exist? You didn't test for it; you tested for a directory of that name.

The same comments apply to the next section as well.
Quote:
Code:
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
  #6 (permalink)  
Old 01-03-2009
em23's Avatar
em23 em23 is offline
Registered User
  
 

Join Date: May 2008
Location: Chicago
Posts: 31
Quote:
Originally Posted by cfajohnson View Post

What are you trying to move? You haven't checked whether there is a file (or directory) called conf in the current directory.

How do you know that /etc/dmi/conf doesn't exist? You didn't test for it; you tested for a directory of that name.

The same comments apply to the next section as well.
Do you mean test, like so:


Code:
test -d /etc/dmi/conf
if [ "$?" -eq 0 ]
then
   print '/etc/dmi/conf does exist'
else
   print '/etc/dmi/conf does NOT exist'
fi

and when executed...
em23@sparky:~$ ./test.sh
/etc/dmi/conf does exist
  #7 (permalink)  
Old 01-03-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,378
Quote:
Originally Posted by em23 View Post
Do you mean test, like so:

test is a synomym for [.
Quote:

Code:
test -d /etc/dmi/conf
if [ "$?" -eq 0 ]

That's the same as


Code:
test -d /etc/dmi/conf
if test "$?" -eq 0

It would normally be written as:


Code:
if test -d /etc/dmi/conf

Or:


Code:
if [ -d /etc/dmi/conf ]

Quote:
Code:
then
   print '/etc/dmi/conf does exist'
else
   print '/etc/dmi/conf does NOT exist'
fi

and when executed...
em23@sparky:~$ ./test.sh
/etc/dmi/conf does exist
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0