Solved

Shell script

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

707 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

12 Experts available now in Live!

Get 1:1 Help Now