Simple if script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple if script
# 8  
Old 04-08-2014
Quote:
Originally Posted by SriniShoo
It's double equal to "=="

Code:
if [ "$5" == '0' ]
  then
    touch /u03/backups/backup_ended.flag
else
    touch /u03/backups/backup_failed.flag
fi

[..]
Like Don mentioned: the proper syntax is a single = sign [ "$5" = 0 ] . Even though some shells tolerate == , it is not portable.
# 9  
Old 04-08-2014
Quote:
Originally Posted by richs24
if i do an

echo $SHELL

it comes back with

/sbin/sh

if that changes anything?
Not really, other than now we can make an educated guess and say that you are using a Solaris system.

To know what shell you're using for this script, we need to know how the script was invoked, and, unless it was invoked by giving its filename as an operand to a command interpreter, we need to see the 1st few lines of the script itself. Since you said earlier that the 1st line of the script is:
Code:
#! /bin/sh

so this script is probably being run by a Bourne shell.

Saying:
Quote:
Thanks for the suggestion Don, it didnt work though. I know that the bpend script is being called at the end of the backup as just having a simple "touch filename" create the file.
doesn't help us help you. How did you determine that it didn't work? Did it touch the wrong file? Did it issue a diagnostic message? Did it fail to touch either file?

Please get into the habit of supplying details about what happened and about what didn't work so the volunteers here can more accurately diagnose what is going on and help you find a solution to your problems expeditiously.

Using a Bourne shell:
Code:
if [ "$5" == '0' ]
     and
if [ '$5' == '0'

should both issue a diagnostic message,
but:
Code:
if [ "$5" = '0' ]
     and
if [ "$5" -eq '0' ]

should both work correctly and produce the same results as long as $5 expands to an integer that fits into a int or a long depending on the vintage of the shell. I prefer the 1st form because it will also correctly test for equality even if the given argument is an empty string, a number that is out of the range supported for arithmetic operations by your shell, or contains text instead of numeric value.

Please add the following statement as a new line of code just before your if statement:
Code:
printf 'Before if: $5 is "%s"\n' "$5"

run the script again, and tell us exactly what happened.
# 10  
Old 04-08-2014
It could also be the statically linked version of the POSIX shell on HPUX .
# 11  
Old 04-08-2014
Quote:
It could also be the POSIX shell on HPUX .
Don was right, it is Solaris.

ive attached an unmodified version of the bpend script that i am trying to put my if statement into, if that helps.
ive not been able to run Don's test yet as the server is having some patches applied.

this script runs as part of a backup using Netbackup. so the backup will run, and when it completes, it will trigger this script if it exists (it doesnt have to exist, its used for running post backup commands).
so all i'm trying to do is to get it to create a flag file that says "successful" is the backup status is 0, and "failed" if it isnt 0

---------- Post updated at 04:49 PM ---------- Previous update was at 04:46 PM ----------

ah, it wont let me upload, i will paste it in instead

Code:
#! /bin/sh
# $Header: bpend_notify.sh,v 1.3 2003/08/13 14:11:54 $
#
#bcpyrght
#***************************************************************************
#* $VRTScprght: Copyright 2013 Symantec Corporation, All Rights Reserved $ *
#***************************************************************************
#ecpyrght
#
# bpend_notify.sh
#
# This script is called by NetBackup when bpbkar is finished doing a
# backup on the client. It is also called after backing up the files
# for a user directed archive, but before the files are deleted.
#
# This script:
#     receives 5 parameters: CLIENTNAME POLICYNAME SCHEDNAME SCHEDTYPE STATUS
#     must be executable by the root user
#     should exit with 0 upon successful completion
#
# If this script will not complete within a few seconds, you should set
# the BPEND_TIMEOUT in the /usr/openv/netbackup/bp.conf file on the server.
# You should also be aware that the time taken by this script will slow
# down other backups that are waiting for this client to complete.
#
# This script should be installed with mode 555 so that user directed
# backups and archives will be able to execute this script.
#
# CAUTION:  writing anything to stdout or stderr will cause backup problems
#



# --------------------------------------------------------------------
# main script starts here
# --------------------------------------------------------------------

umask 022

if [ "$#" -ne 5 ]
then
      exit 1
fi

if [ "$4" = "FULL" -o "$4" = "INCR" -o "$4" = "CINC" ]
then
        OUTF=/usr/openv/netbackup/bin/BPEND_CALLED

      # You may want to delete the output file elsewhere in order to
      # accumulate successful backup information.
      # If so, comment out the following 4 lines. 
      if [ -s $OUTF ]
      then
            /bin/rm -rf $OUTF
      fi

      if [ ! -f $OUTF ]
      then
            touch $OUTF
      fi

      case "$4"
      in
            "FULL")
                  echo `date` full backup finished on $1 - policy $2 schedule $3. Exit status = $5 >> $OUTF
                  ;;
            "INCR")
                  echo `date` differential incremental backup finished on $1 - policy $2 schedule $3. Exit status = $5 >> $OUTF
                  ;;
            "CINC")
                  echo `date` cumulative incremental backup finished on $1 - policy $2 schedule $3. Exit status = $5 >> $OUTF
                  ;;
      esac

      #
      # might want to mail this info to someone
      #
      # cat $OUTF | mail -s "NetBackup backup finished" someone_who_cares
      #
      # CAUTION:  some platforms do not allow the -s parameter on mail
      #
fi

exit 0

# 12  
Old 04-08-2014
Can you show us the contents of /usr/openv/netbackup/bin/BPEND_CALLED from the last run?
# 13  
Old 04-08-2014
Tue Apr 8 16:17:20 BST 2014 cumulative incremental backup finished on hadn-ppof-001 - policy PPF_CTC_ORA_IL3_daily schedule DailyInc. Exit status = 0
# 14  
Old 04-08-2014
Given what we now know, I see no reason why:
Code:
if [ "$5" = '0' ]
then
        touch /u03/backups/backup_ended.flag
else
        touch /u03/backups/backup_failed.flag
fi

should not work if you insert those lines just before the exit statement at the end of your script.

Please also add the lines:
Code:
set -xv
exec 2>/usr/openv/netbackup/bin/BPEND_TRACE

just before the above code and show us the contents of /usr/openv/netbackup/bin/BPEND_TRACE after the script runs again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple script

I have to pull files from a customers cloud directory to our cloud directory periodically, the customer has the files in the new-version(nver) folder; which I am pulling via a python script. (python nver.py) customers cloud location: s3://custbucket/$nver/files Our cloud location:... (0 Replies)
Discussion started by: ramky79
0 Replies

2. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Simple Script Can u help please?

I have a file that contains these lines User ID Username -------- ---------- 7738626,zrazak 7783535,jvincigu 7805567,ldrennan 7805583,mtsakama I need to sort the names alphabetically How can I sort the lines based on the user names ? I would appreciate a quick reply anyone ... (1 Reply)
Discussion started by: mnassiri
1 Replies

5. Shell Programming and Scripting

Simple Script to do so?

hi guys, i am a noob to shell scripting, and i would like to run a simple script, that could simply do the following: 1. SFTP to a remote server/path...and download the newest *.gz backup file on that server. (there are many *.gz files in that folder, i simply need the latest one) 2. locally... (1 Reply)
Discussion started by: Confidence
1 Replies

6. Shell Programming and Scripting

Simple script

I have a script that will check for integer line by line and if it encounter any blank space will echo it: Below the script: #!/bin/ksh while read i do echo "Value is $i" count=`expr substr "$i" 1 3` echo $count if && then echo "Matched" else echo "Blank Space Found" fi (3 Replies)
Discussion started by: ali560045
3 Replies

7. UNIX for Dummies Questions & Answers

Simple script

I am trying to print my script arguments, but i am stuck at the arrow pointed lines..please help #!/bin/bash echo "Number of arguments $#" count=1 while do echo ${$count} <======================== count = $(expr $count +1) <================== done (4 Replies)
Discussion started by: chvs2000
4 Replies

8. Shell Programming and Scripting

simple script

Hi, I just need a shell script to find out the processes taking longer time...(Unix/Linux) Urgent response needed.. Rajiv (5 Replies)
Discussion started by: rajivn786
5 Replies

9. Shell Programming and Scripting

Simple Script

Here is the script that i am trying to run. I get an error and i can't figure out what is the problem. #!/bin/bash echo "What is your name" read NAME if ; then echo "My name is the same" esle echo "You have a nice name" fi (11 Replies)
Discussion started by: xplod4202
11 Replies

10. UNIX for Dummies Questions & Answers

help with simple script

I need a script that checks to see if ypserv is running, and if not it will restart yp. I have a ypslave that is running Sol9, and the ypsrv daemon is dieing, I want to create a cron job that periodicly checks to see if it's running, and if it see's that it isn't, it will re-start the daemon (1 Reply)
Discussion started by: jdel80
1 Replies
Login or Register to Ask a Question