Solved Help required For/While Loop in my script

February 6, 2018 at 10:26:53
Specs: AIX
I have coded a script for checking the status of the MKSYSB Backup in my project. In this script it will first check for the status of the MKSYSB backup if the backup is sucessfull then those backup will be moved to our centralized server ......if the status of the backup shows it is failed.....then it will reinitiate the backup manually upto that it is working fine.....and once it finishes with manual backup again it needs check for the status of the backup and needs to display the results.

#!/bin/sh
file=$(find /td/logs/backups/`hostname`.log.* -xdev -mtime -1)

word="stack_backup done"
cmd=$(grep -ci "$word" $file)

if [ "$cmd" != "0" ]; then

echo "MKSYSB was successful on `hostname`"

sleep 10

echo "NFS Mount to NIM server in progress..."

mkdir mnt4

mount uosnim23:/export/nim2/epm-unix/mksysbs/DEV /mnt4

sleep 10

echo "Backup movement in progress...."

cp -rp /td/mgmt/backups/`hostname`.mksysb.* /mnt4

echo "Backup has been copied successfully to uosnim23 server"

umount -f /mnt4

else
echo "MKSYSB was not successful `hostname`"

sleep 10

echo "Manual MKSYSB backup has been initiated"

/usr/bin/find /td/mgmt/backups -type f -mtime +0 -exec /usr/bin/rm -f {} ";" ;/td/mgmt/bin/stack_backup

fi


See More: Help required For/While Loop in my script

Report •

#1
February 9, 2018 at 07:20:26
✔ Best Answer
I am assuming you want to implement a while loop for each $file found in your find command:

file=$(find /td/logs/backups/`hostname`.log.* -xdev -mtime -1)

Do something like this:

# Untested
find /td/logs/backups/`hostname`.log.* -xdev -mtime -1|while read file
do
# place your script operating on 'file' here
done

message edited by nails


Report •
Related Solutions


Ask Question