Sponsored Content
Top Forums Shell Programming and Scripting Backup script using Korn Flow Control Post 302567299 by metallica1973 on Monday 24th of October 2011 05:16:03 PM
Old 10-24-2011
awesome,

I will try the exit 1. I tried that before but with just an exit in both else statements and I still had issues but will give it another shot. I will also add what you had suggested with the ping stuff, you made it clear that what I was doing wouldnt have worked as designed. Will let you know how it goes.

Regards

---------- Post updated 10-24-11 at 10:39 AM ---------- Previous update was 10-23-11 at 10:36 PM ----------

It appears to have worked except now when I do not specify "full or incremental, it proceeds to execute the "Full Backup" else statement instead of flagging incorrect syntax usage from my case area:

Code:
sudo ksh -x ./backup.ksh 
+ results=''
+ home=/home/testuser
+ backup_dir=/media/caca/extract
+ date +%m%d%y
+ date=102411
+ date
+ reg_date='Mon Oct 24 10:27:13 EDT 2011'
+ whoami
+ id_check=root
+ search=find
+ archive='cpio -oavc'
+ mail_to=me@testemail.com
+ sendto=/usr/bin/mutt
+ remote_host=192.168.0.32
+ ping -c 2 192.168.0.32
+ 1> /dev/null 2>& 1
+ ping_stat=1
+ (( 1 == 0 ))
+ echo ''
+ 1> /media/caca/extract/fullerror102411.log
+ echo ' Mon Oct 24 10:27:13 EDT 2011  ----------Full Backup Error Log----------                           '
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ''
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ' Make sure you are root and backup share is mounted on server **/media/backup_drive** '
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ' The Full' 'Backup did not execute for one of the Following reasons:      '
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ''
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ' 1 - Ran as non-root user                                                 '
+ 1>> /media/caca/extract/fullerror102411.log
+ echo $' 2 - Share not mounted\t\t\t\t\t\t\t'
+ 1>> /media/caca/extract/fullerror102411.log
+ echo $' 3 - Incorrect Syntax\t\t\t\t\t\t\t'
+ 1>> /media/caca/extract/fullerror102411.log
+ /usr/bin/mutt -s 'Daily MYSQL Log' me@testemail.com
+ 0< /media/caca/extract/fullerror102411.log
+ exit 1

What should have been executed:

Code:
*)echo "Incorrect syntax usage. Use <backup.ksh> {full|incremental} or target directory does not exist. Please verify share exist";;

I no it the smallest little thing. I am missing something somewhere ??

---------- Post updated at 12:13 PM ---------- Previous update was at 10:39 AM ----------

It appears to have worked except now when I do not specify "full or incremental, it proceeds to execute the "Full Backup" else statement instead of flagging incorrect syntax usage from my case area:


Code:
sudo ksh -x ./backup.ksh 
+ results=''
+ home=/home/testuser
+ backup_dir=/media/caca/extract
+ date +%m%d%y
+ date=102411
+ date
+ reg_date='Mon Oct 24 10:27:13 EDT 2011'
+ whoami
+ id_check=root
+ search=find
+ archive='cpio -oavc'
+ mail_to=me@testemail.com
+ sendto=/usr/bin/mutt
+ remote_host=192.168.0.32
+ ping -c 2 192.168.0.32
+ 1> /dev/null 2>& 1
+ ping_stat=1
+ (( 1 == 0 ))
+ echo ''
+ 1> /media/caca/extract/fullerror102411.log
+ echo ' Mon Oct 24 10:27:13 EDT 2011  ----------Full Backup Error Log----------                           '
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ''
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ' Make sure you are root and backup share is mounted on server **/media/backup_drive** '
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ' The Full' 'Backup did not execute for one of the Following reasons:      '
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ''
+ 1>> /media/caca/extract/fullerror102411.log
+ echo ' 1 - Ran as non-root user                                                 '
+ 1>> /media/caca/extract/fullerror102411.log
+ echo $' 2 - Share not mounted\t\t\t\t\t\t\t'
+ 1>> /media/caca/extract/fullerror102411.log
+ echo $' 3 - Incorrect Syntax\t\t\t\t\t\t\t'
+ 1>> /media/caca/extract/fullerror102411.log
+ /usr/bin/mutt -s 'Daily MYSQL Log' me@testemail.com
+ 0< /media/caca/extract/fullerror102411.log
+ exit 1

What should have been executed:


Code:
*)echo "Incorrect syntax usage. Use <backup.ksh> {full|incremental} or target directory does not exist. Please verify share exist";;

I no it the smallest little thing. I am missing something somewhere ??

---------- Post updated at 05:16 PM ---------- Previous update was at 12:13 PM ----------

I made another adjustment,fixed some of the logic and it fixed my issues. I created a pinger function and just called it when I needed it as opposed to using a variable constant:

Code:
pinger ()
{
remote_host=192.168.0.32
ping -c 1 $remote_host >/dev/null 2>&1
ping_stat=$?
}
##############

if [[ $id_check == "root" && -d $backup_dir &&  $results == "full" ]] ; then

                pinger

                if [[ $ping_stat -eq 0 ]] ; then
        cd $home
        ......

I also added exit 1's at the end of conditions

Code:
$sendto -s "Daily Backup Log" $mail_to  < $backup_dir/inc$date.log
exit 1
...

I will paste the finish product in a few.

Last edited by metallica1973; 10-24-2011 at 11:45 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to assign correct control flow?

how can i create a script with a correct control flow/loop(?) to provide output from 3 files? file1 one two three file2 yellow red orange file3 banana apples cantaloupes output file: one (1 Reply)
Discussion started by: apalex
1 Replies

2. Shell Programming and Scripting

Tape backup control

Hi all I have a requirement to ensure I do not overwrite a tape that is current. The way in which I propose doind this is by placing a header file at the beginning of the tape containing the creation date of the backup. Before each backup, I will read this file and validate. My question is as... (4 Replies)
Discussion started by: jhansrod
4 Replies

3. Programming

dilemma in control flow

hello im facing a queer problem when i execute the foll code in unix # include <stdio.h> # include <unistd.h> main(int argc,char *argv) { FILE *fp = fopen("/ras/chirag/fifotest/file.fifo","a"); int i=1; fprintf(fp,argv); printf("I SLEEP"); system("date"); for (i=0;i<50;i++)... (2 Replies)
Discussion started by: tej.buch
2 Replies

4. IP Networking

Disabling 802.3x flow control

I have a server I would like to disable 802.3x flow control on. The host is Linux (CentOS 4.4 x86_64 w/ 2.6.9-42.0.3.EL kernel,) and I'm using the ns83820 driver for the ethernet interface in question. I've tried looking at the driver parameters (modinfo ns83820) and using ethtool (ethtool -a... (0 Replies)
Discussion started by: LivinFree
0 Replies

5. UNIX for Advanced & Expert Users

Script should flow after ftp --Urgent

Hi everyone, The script actually does the ftp and gets the file to the local system. I want to do some manipulations for that file , But after doing ftp , script is not proceding and just a prompt is displayed . .... ftp code here...... .................... ............... echo "FTP... (4 Replies)
Discussion started by: kaaakrishna
4 Replies

6. Shell Programming and Scripting

Python script - control flow statements

Hi guys.I'm just beginner of python. I'm just trying to do some analysis on simple input file. it has 6 columns and i want to consider k,l and m,n if i and j are + after that checking which value is greater or lower in k,l and m,n I have included logic header just to explain what I was... (4 Replies)
Discussion started by: repinementer
4 Replies

7. Shell Programming and Scripting

Flow Control in CSH

hi , I am new to scripting, i have a doubt can any one pls solve it for me the code is not working set users = (user1 user2 user3) echo The users are echo $users echo Enter the USER NAME set USER_NAME = $< set i = 1; for ( i = 1; i <= $#users; i++ ) if ( $USER_NAME == $users )... (1 Reply)
Discussion started by: Manju87
1 Replies

8. Shell Programming and Scripting

Ampersand not giving back the control (Korn shell)

OS version : AIX 6.1 Shell : Korn When you 'postfix' a command with ampersand (&) , it is supposed to run in the background and give you back the control. I tested this with ping command (by default it pings every 1 second ) After I ran the below ping command with ampersand, I pressed... (3 Replies)
Discussion started by: polavan
3 Replies

9. Shell Programming and Scripting

Help with control flow in a Bash script

In my bash script I want to say "if argument 2 is anything except x, y or z, than echo this" (x y and z being words). So my script looks like this: if ] then echo "unrecognized input: $2" fi This usually works but than I also want to say "if argument 2 IS x, y, or z, but argument 4 is... (4 Replies)
Discussion started by: Jrodicon
4 Replies

10. UNIX for Dummies Questions & Answers

Flow control state changed in server logs

Hi, We observe below logs from switch - the database servers rebooted becaause they couldn't do I/O on vfiler -Any pointers looking at below logs please? Switch logs: 2016 Apr 30 07:41:16.729 EAG-ECOM-POD111GPU-SWF1 %ETHPORT-5-IF_DOWN_LINK_FAILURE: Interface Ethernet152/1/8 is down (Link... (0 Replies)
Discussion started by: admin_db
0 Replies
All times are GMT -4. The time now is 01:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy