Solved

Shell script

Posted on 2011-03-14
2
442 Views
Last Modified: 2013-12-28
Hi Friends,
Need your help to draft shell script which will perform following functions.
Source file, which contains first argument as server name, second argument filesystem type and third is command to take backup.

Filename - servername.txt
Servername:/var/log:arc
Servername:/var/:backup
Servername:/var/log:qfiles
Servername:/var/log:arc

The script will first scan the servername.txt file, and depending on the second and third argument it will execute shell script.
If the second and third argument is “/var/log” and “arc” then it will execute the script 1
If the second and third argument is “/var/” and “backup” then it will execute sscript2
If the second and third argument is “/var/log” and qfiles  then it will excute script3
If the second and third argument is “/var” and “qfiles” then execute script4
Else argument specified is not valid.
Thanks
0
Comment
Question by:rameshsukhi123
2 Comments
 
LVL 12

Expert Comment

by:Amick
ID: 35125878
for spath in $(cut -d: -f2-3 servername.txt)
do
case $spath in
/var/log:arc)
	echo script1 ;;
/var/:backup)
	echo script2 ;;
/var/log:qfiles)
	echo script3 ;;
/var/:qfiles)
	echo script4 ;;
*)
	echo spath not processed. ;;
esac
done

Open in new window

of course instead of echo you'll want to execute the appropriate script.
0
 
LVL 8

Accepted Solution

by:
point_pleasant earned 500 total points
ID: 35128691
amick's script will not work to execue script4 should be "/var:qfiles"  hear is a script that actually gets both variables (i.e. the filesystem type on the back up type).  should also be easire to add more filesystems and backup types.


Mike

for i in `cat ./bck.tct`
do
        file_system=`echo $i | cut -f2 -d:`
        back_up_type=`echo $i | cut -f3 -d:`
        case $file_system in
        /var/log)
                case $back_up_type in
                        arc)
                                echo script1
                                ;;
                        qfiles)
                                echo script3
                                ;;
                        *)
                                echo "SPECIFIED ARGUEMENT NOT VALID"
                                ;;
                esac
        ;;
        /var/)
                case $back_up_type in
                        backup)
                                echo script2
                                ;;
                        *)
                                echo "SPECIFIED ARGUEMENT NOT VALID"
                                ;;
                esac
                ;;
        /var)
                case $back_up_type in
                        qfiles)
                                echo script4
                        ;;
                        *)
                                echo "SPECIFIED ARGUEMENT NOT VALID"
                        ;;
                esac
        ;;
        *)
                echo "SPECIFIED ARGUEMENT NOT VALID"
                ;;
        esac
done
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question