Question : Scripting newbie question

Hi Friends,

i need to know some things about bash scripting

First how can i make my attached script shorter?

Second how to make my script executable from whole system ...meaning if i have made script in /tmp/scripts dir then rather then using /tmp/scripts/select1.sh i simple type ./select1.sh or type selcet.sh anywhere in the system it shold run.

Thanks For being with me
bashcool
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
#!/bin/bash
PS3='Please select the choice: '
 
LIST="Ping-DNS Ping-XP Check-Hostname  Check-System-log Check-maillog Check-open-ports Check-ip Change-DNS Change-network-settings  quit"
 
select mast in $LIST
 
do
 
if [ $mast = "Ping-DNS" ];then
 
ping -c2 172.24.254.2
 
elif [ $mast = "Ping-XP" ];then
 
ping -c2 172.24.254.55
 
elif [ $mast = "Check-Hostname" ];then
 
hostname -f
 
elif [ $mast = "Check-System-log" ];then
tail -n4 /var/log/messages
 
elif [ $mast = "Check-maillog" ];then
tail -n4 /var/log/maillog
 
elif [ $mast = "Check-open-ports" ];then
netstat -ntulp 
 
elif [ $mast = "Check-ip" ];then
ifconfig | grep "inet addr"
 
elif [ $mast = "Change-network-settings" ];then
vi /etc/sysconfig/network-scripts/ifcfg-eth0
 
elif [ $mast = "Change-DNS" ];then
vi /etc/resolve.conf
 
elif [  $mast = "quit" ];then
 
exit
 
fi
 
done
Open in New Window Select All

Answer : Scripting newbie question

OK Here's the complete list:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
#!/bin/bash
 
while true; do
  echo "Type the command, followed by [ENTER]:"
 
  read mast
 
  echo -n $mast
 
  case "$mast" in
    'Ping-DNS' )        ping -c2 174.24.254.55
                        ;;
 
    'Ping-XP' )         ping -c2 172.24.254.55 
                        ;;
                 
                 
     'Check-Hostname')  hostname -f
                        ;;
 
     'Check-System-log') tail -n4 /var/log/message
                        ;;       
                 
      'Check-maillog')  tail -n4 /var/log/maillog
                        ;;
                        
      'Check-open-portS') netstat -ntulp
                        ;; 
 
      'Check-ip')       ifconfig | grep "inet addr"
                        ;;
                        
      'Change-network-settings' ) vi /etc/sysconfig/network-scripts/ifcfg-eth0
                        ;;  
 
      'Change-DNS')     vi /etc/resolve.conf                        
                        ;;
   
      'quit')           exit 1
                        ;;       
 
    *)  echo "Usage:"
        echo  $(basename $0)  "[Ping-DNS] | [Ping-XP] | [Check-Hostname] | [Check-System-log] |"
        echo  "                  [Check-maillog] | [Check-open-ports] | [Check-ip] | [Change-DNS] |" 
        echo  "                  [Change-network-settings | [quit]"
         ;;
   esac
Open in New Window Select All
Random Solutions  
 
programming4us programming4us