Sponsored Content
Top Forums Shell Programming and Scripting usage of case statement in place of IF elif... Post 302360270 by aemunathan on Thursday 8th of October 2009 12:56:25 PM
Old 10-08-2009
usage of case statement in place of IF elif...

Hi,

I need to carry out the back up of the data if exists...(file size not equal to zero)

i tried in this way but it is not successful....where am making the mistakes? and if possible can i use case syntax in place of "if"

Code:
#!/bin/ksh
filename=`TZ=CST+24 date +%Y%m%d`
ZERO=0
SIZE_64=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-64.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_71=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-71.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_72=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-72.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_73=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-73.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_80=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-80.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_EZ=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-EZ.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_WZ=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-WZ.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_NZ=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-NZ.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_MTNL=$(ls -ltr /aemu/ErrorLogs/data/MissingCGI-MTNL.txt | tr -s ' ' | cut -d ' ' -f 5)
SIZE_COUNT=$(ls -ltr /aemu/ErrorLogs/data/MissingCGIcount.txt | tr -s ' ' | cut -d ' ' -f 5)



if [ $SIZE_64!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-64.txt /aemu/ErrorLogs/backup/CHN/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-64.txt > /aemu/ErrorLogs/data/MissingCGI-64.txt

elif [ $SIZE_71!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-71.txt /aemu/ErrorLogs/backup/KTK/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-71.txt > /aemu/ErrorLogs/data/MissingCGI-71.txt
        
elif [ $SIZE_72!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-72.txt /aemu/ErrorLogs/backup/KER/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-72.txt > /aemu/ErrorLogs/data/MissingCGI-72.txt

elif [ $SIZE_73!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-73.txt /aemu/ErrorLogs/backup/AP/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-73.txt > /aemu/ErrorLogs/data/MissingCGI-73.txt

elif [ $SIZE_80!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-80.txt /aemu/ErrorLogs/backup/TN/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-80.txt > /aemu/ErrorLogs/data/MissingCGI-80.txt
        
elif [ $SIZE_EZ!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-EZ.txt /aemu/ErrorLogs/backup/EZ/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-EZ.txt > /aemu/ErrorLogs/data/MissingCGI-EZ.txt

elif [ $SIZE_WZ!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-WZ.txt /aemu/ErrorLogs/backup/WZ/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-WZ.txt > /aemu/ErrorLogs/data/MissingCGI-WZ.txt
        
elif [ $SIZE_NZ!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-NZ.txt /aemu/ErrorLogs/backup/NZ/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-NZ.txt > /aemu/ErrorLogs/data/MissingCGI-NZ.txt
        
elif [ $SIZE_MTNL!=$ZERO ]
        then
        cp /aemu/ErrorLogs/data/MissingCGI-MTNL.txt /aemu/ErrorLogs/backup/MTNL/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGI-MTNL.txt > /aemu/ErrorLogs/data/MissingCGI-MTNL.txt
        
else [ $SIZE_COUNT!=$ZERO ]
        cp /aemu/ErrorLogs/data/MissingCGIcount.txt /aemu/ErrorLogs/backup/COUNT/$filename
sleep 2
        sed '' /aemu/ErrorLogs/data/MissingCGIcount.txt > /aemu/ErrorLogs/data/MissingCGIcount.txt
        
fi

exit

Aemunathan
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

case statement

Hi all, is it possible to create a 'dynamic' case statement. ie select option in `ls` do case satement depending on results of the above `ls` done I hope I have explained this ok! Thanks Helen (1 Reply)
Discussion started by: Bab00shka
1 Replies

2. UNIX for Dummies Questions & Answers

Help with ELIF statement

I am receiving an elif error on line 13 and I can not figure out the reasoning behind it. I have added the then statement that I was initially missing. Any help would be great. #The purpose of this script is for the end user to be able to enter a positive number #User enters a number NUM=$1... (4 Replies)
Discussion started by: Brewer27
4 Replies

3. Shell Programming and Scripting

How can I place a for statement....

In a script? I have some folders that contain many files of 8MB or more in size. Every day run "for file in F*; do gzip $file; done" How can I put this in a script to run automatically? (7 Replies)
Discussion started by: bbbngowc
7 Replies

4. UNIX for Dummies Questions & Answers

If or Case Statement

I want to write a program with the following variables: a=7000 b=24000 c=613.8 The user can enter two words: Vivid or Blue for example. The challenge is that the user might not want to write the words the way they appear. The user can write V or v or vivid or Vivid or write Blue or blue, or B,... (1 Reply)
Discussion started by: Ernst
1 Replies

5. Shell Programming and Scripting

case statement

Hi all, I think i'm asking a sqtupid question here.. i'm using case sttament, what is the syntax or symbol for "or"? I thought was || here a quick sample of my case statment echo "Would you like to update your detail ?" read response case $response in ... (2 Replies)
Discussion started by: c00kie88
2 Replies

6. Shell Programming and Scripting

help with case statement

I am writing a script to pull diskspace information from our servers. Here is the script that I wrote: #!/bin/ksh for host in `cat /oper/hosts/esc.misc` do ssh -q -o ConnectTimeout=10 operator@$host df -h|grep "/dev/" |egrep '8%|9%|100%' | awk '{print H " " "at " $5 " with " $4 "... (1 Reply)
Discussion started by: rkruck
1 Replies

7. Shell Programming and Scripting

case statement

Hi, I am writing case statement to execute some finction, my requirement is once one of the case statement is executed again it has to prompt for the option. for script in `echo "$Script_Selected"` do case $script in 1) getNoOFActUsers ;; 2) moveServerrOORotation ;; ... (2 Replies)
Discussion started by: Satyak
2 Replies

8. Shell Programming and Scripting

Case Statement

Hey, guys I really need some help with a project. "Write a shell program that examines the command line arguments, counts and collects the number of options. Basically it has to collect and count the arguments that start with a "-" and the one's that don't start with a - I know I have to use... (2 Replies)
Discussion started by: sk192010`
2 Replies

9. Homework & Coursework Questions

Case Statement

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hey, guys I really need some help with a project. "Write a shell program that examines the command line... (8 Replies)
Discussion started by: sk192010`
8 Replies

10. Shell Programming and Scripting

Convert to case statements from if/elif

Hello, I wrote the case on code but it mistakes. I am not sure. If/elif code: #!/bin/ksh you=$LOGNAME hour=`date | awk '{print substr($4, 1, 2)}'` print "The time is: $(date)" if (( hour > 0 && $hour < 12 )) then print "Good morning, $you!" elif (( hour == 12 )) then (7 Replies)
Discussion started by: Masterpoker
7 Replies
unifdef(1)						      General Commands Manual							unifdef(1)

NAME
unifdef - Removes #ifdefed lines SYNOPSIS
unifdef [-tlc] [-Dsymbol] [-idsymbol] [-iusymbol] [file] [-Usymbol] The unifdef command partially simulates the behavior of the C preprocessor in processing #ifdef conditionals. OPTIONS
Complements the action of unifdef; retains lines that would normally be removed and removes lines that would normally be retained. Speci- fies symbol as a defined #ifdef symbol. Specifies defined lines inside certain #ifdefs to be ignored but copied out. Specifies undefined lines inside certain #ifdefs to be ignored and not copied out. Replaces removed lines with blank lines instead of deleting them. Pro- cesses plain text (rather than C code) input. The unifdef command does not try to recognize comments, single quotes, and double quotes. Specifies symbol as an undefined #ifdef symbol. DESCRIPTION
The unifdef command recognizes nested #ifdefs, comments, single and double quotes of C syntax so that it can function correctly, but does not include files or interpret macros. The unifdef command recognizes, but does not remove comments. The unifdef command takes its input from stdin if no file argument is given, and copies its output to stdout. You specify the symbols you want defined with -Dsymbol or undefined with -Usymbol and the lines inside those #ifdefs are copied to the out- put or removed, as appropriate. The #ifdef, #ifndef, #else, #elif, and endif lines associated with symbol are also removed. The #ifdefs involving unspecified symbols are untouched and copied out along with their associated #ifdef, #else, elif, and #endif lines. If the same symbol appears in more than one argument, only the first occurrence is significant. For instance, if an #ifdef X occurs nested inside another #ifdef X, the inside #ifdef is considered an unrecognized symbol. If you use #ifdefs to delimit non-C lines, such as comments or unfinished code, it is necessary to specify which symbols are to be used for that purpose. Otherwise, the unifdef command tries to parse for quotes and comments in those #ifdef lines. Keywords The following keywords can be used with the unifdef command: ifdef ifndef else endif elif The unifdef command uses the elif keyword as follows. (Note that "Understood" means unifdef knows how to convert elif to if.) Understood Not understood Not understood For example: # ifdef X x # elif defined (Y) y # elif defined (A) || defined (B) a # else default # endif The following list shows the results of using the elif keyword with variables: -DX x -UX # if defined (Y) y # elif defined (A) || defined (B) a # else default # endif -UX -DY y -UY -UX # if defined (Y) y # elif defined (A) || defined (B) a # else default # endif -UY -UX -DA # if defined (Y) y # elif defined (A) || defined (B) a # else default # endif NOTES
The unifdef command cannot process cpp constructs such as: #if defined(X) || defined(Y) DIAGNOSTICS
The unifdef command can fail for several reasons: a premature end of file, or an inappropriate else, elif, or endif. EXIT STATUS
Exit status is 0 if output is an exact copy of input, 1 if not, 2 if the unifdef command fails. EXAMPLES
The following command line causes the unifdef command to read the file original.c and remove the #ifdef A lines. It then removes every- thing following an #elif/#else associated with the #ifdef A down to the #endif: unifdef -DA original.c > modified.c The following command line causes the unifdef command to read the file original.c, and remove the #ifdef A down to either its associated #elif/#else, or its associated #endif: unifdef -UA original.c > modified.c In the case of the #elif, the #elif is replaced with #if. In the case of #else, the #else is deleted along with its associated #endif. SEE ALSO
Commands: diff(1) unifdef(1)

Featured Tech Videos

All times are GMT -4. The time now is 08:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy