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
dos2unix(1)						      General Commands Manual						       dos2unix(1)

NAME
dos2unix - DOS/MAC to UNIX text file format converter SYNOPSYS
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents dos2unix, the program that converts plain text files in DOS/MAC format to UNIX format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates dos2unix under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. dos2unix Convert and replace a.txt. Convert and replace b.txt. dos2unix a.txt b.txt dos2unix -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. Convert c.txt from Mac to Unix ascii format. dos2unix a.txt -c iso b.txt dos2unix -c ascii a.txt -c iso b.txt dos2unix -c mac a.txt b.txt Convert and replace a.txt while keeping original date stamp. dos2unix -k a.txt dos2unix -k -o a.txt Convert a.txt and write to e.txt. dos2unix -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. dos2unix -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. dos2unix a.txt -n b.txt e.txt dos2unix -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHORS
Benjamin Lin - <blin@socs.uts.edu.au> Bernd Johannes Wuebben (mac2unix mode) <wuebben@kde.org> MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
unix2dos(1) mac2unix(1) 1995.03.31 dos2unix v3.0 dos2unix(1)
All times are GMT -4. The time now is 12:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy