Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Shell script

Posted on 2011-03-14
2
Medium Priority
?
451 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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.
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

916 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