Script ready but might need some improvement.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script ready but might need some improvement.
# 1  
Old 07-02-2008
Script ready but might need some improvement.

Hi All,
I have written a script which does some editing in the files, based on user input.This might not be the most elegant way of doing it and there would be many improvements needed.

Please go through it and let me know how it could be improved.

Suggestions are welcome!!

Thanks!
nua7

Code:
#!/bin/ksh
# DESCRIPTION : This script will make changes in the following files:         #
#               a)/etc/sysconfig/network-scripts/ifcfg-eth0                   #
#               b)/etc/hosts                                                  #
#               c)/etc/sysconfig/network                                      #
#               d)/etc/security/access.conf                                   #
#checking the variables passed
if [ $# -lt 2 ] ; then
      echo need 2 files  
      exit 0
fi
######
# Ensuring that only root can run this script
######
logonID=`whoami`
if test "$logonID" != "root"
then
  echo "\nYou should logon as MGR for running this script"
  exit
fi
#setting up variables
ips=$1
domain_name=".xyz.abc.com"
mc_name=$2
export ips
#Modifying the ifcfg-eth0 file
awk -v ip=$ips '/ONBOOT=no/{
print
print "DEVICE=eth0"
print "BOOTPROTO=static"
print "IPADDR=" ip
print "NETMASK=255.255.255.0"
print "GATEWAY=148.147.172.1"
next
}1' /etc/sysconfig/network-scripts/ifcfg-eth0> /etc/sysconfig/network-scripts/temp1
sed -e's/no/yes/' /etc/sysconfig/network-scripts/temp1 > /etc/sysconfig/network-scripts/temp2
rm /etc/sysconfig/network-scripts/ifcfg-eth0
mv /etc/sysconfig/network-scripts/temp2 ifcfg-eth0
chmod 644 /etc/sysconfig/network-scripts/ifcfg-eth0
#Modifying /etc/hosts
echo $ips $mc_name$domain_name $mc_name > /etc/host2
sed -e's/127.0.0.1/#127.0.0.1/' /etc/hosts > /etc/host1
rm /etc/hosts
mv /etc/host1 /etc/hosts
hostname $mc_name
#Modifying access.conf
sed -e's/-:root/#-:root/' /etc/security/access.conf > /etc/security/access1.conf
rm /etc/security/access.conf
mv /etc/security/access1.conf /etc/security/access.conf
echo "Don't forget to reboot the system"

# 2  
Old 07-02-2008
if you are expecting filenames as arguements, how about checking for their existence and making sure that they are readable before continuing further?
say, run your script as:
Code:
scriptname.ksh /foo/bar /dev/full

# 3  
Old 07-02-2008
Thanks Yogesh!
I am taking areguments as strings, the first one would be ip and the other one would be hostname.

But I would remember your suggestion while taking filenames as arguments.

Thanks again!
nua7
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

The disk drive for /tmp is not ready yet or not present && the disk drive for /boot is not ready yet

Hi Team when I boot the server I get this 2 errors : the disk drive for /tmp is not ready yet or not present the disk drive for /boot is not ready yet or not present and its stay like that , I m using Ubuntu 12.04 please if someone have any idea how to fix that problem . (1 Reply)
Discussion started by: SULTAN01
1 Replies

2. UNIX for Dummies Questions & Answers

Improvement in shell script

Hi This is my Following code: #!/bin/sh echo "TOTAL_NO_OF_MAILS" read TOTAL_NO_OF_MAILS echo "TOTAL_NO_OF_TICKETS " read TOTAL_NO_OF_TICKETS echo "TICKETS_IN_QUEUE" read TICKETS_IN_QUEUE rm -rf `pwd`/Focus echo "Hi Team\nSTATS IN CLRS MAIL BOX\n\n==============================" >> Focus... (11 Replies)
Discussion started by: wasim999
11 Replies

3. Shell Programming and Scripting

I need the improvement for my script

Hi All, Here is my script #! /bin/sh var1=some email id var2=some email id grep -i "FAILED FILE FORMAT VALIDATION" /opt >tmp2 diff tmp1 tmp2 | grep ">" >tmp3 if then cat tmp3 | mailx -s " Error Monitoring" $var2 else echo "Pattern NOt Found" | mailx -s " Error Monitoring" $var1... (1 Reply)
Discussion started by: Gopalak
1 Replies

4. Shell Programming and Scripting

Need a ready Shell script to validate a high volume data file

Hi, I am looking for a ready shell script that can help in loading and validating a high volume (around 4 GB) .Dat file . The data in the file has to be validated at each of its column, like the data constraint on each of the data type on each of its 60 columns and also a few other constraints... (2 Replies)
Discussion started by: Guruprasad
2 Replies

5. UNIX for Advanced & Expert Users

linux os improvement

can anyone help to share the knowledge on linux os improvement? 1) os account - use window AD authentication, such as ldap, but how to set /etc/passwd, where to put user home? 2) user account activity - how to log os user activity share the idea and what tools can do that...thx (5 Replies)
Discussion started by: goodbid
5 Replies

6. Shell Programming and Scripting

Looking for improvement to script that compresses a directory that is 2 months old

I write reports daily to a directory that is named with the month and year. I wanted to compress all but the last two months worth of these directories to save space. I am going to cron a job to run on the first of each month to do this clean up. I didn't have zip/unzip on my AIX environment so... (0 Replies)
Discussion started by: slatoms
0 Replies

7. Shell Programming and Scripting

Any improvement possible in this script

Hi! Thank you for the help yesterday This is the finished product There is one more thing I would like to do to it but I’m not to certain On how to proceed I would like to log all output to a log in order to Be able to roll back This script is meant to be used in repairing a... (4 Replies)
Discussion started by: Ex-Capsa
4 Replies

8. Shell Programming and Scripting

Want to execute rest of the script after the file is ready ...

Hi All I have a requirement like, where a file gets generated in a particular dir and once the file is ready and available then I want to execute rest of the script, because untill and unless the file exists and is available there is no use of running rest of the commands in that script. ... (5 Replies)
Discussion started by: csaha
5 Replies
Login or Register to Ask a Question