Solved

Shell script

Posted on 2011-03-14
2
439 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now