Skip to content Skip to sidebar Skip to footer

How To Exit Out Of The Shell Script With Non Zero Status If The Files Are Missing In Both The Machines?

I am running my below shell script from machineA which is copying the files from machineB and machineC into machineA. If the files are not there in machineB, then it should be ther

Solution 1:

If you need get the file name and exist code, try this, you need set for secondary scp as well with different exist code, such as exit 102

# delete first and then copy the files in primary directory
    find "$PRIMARY" -mindepth 1 -delete
    for el in"${PRIMARY_PARTITION[@]}"doif `scp user@${FILERS_LOCATION[0]}:$dir1/t1_weekly_1680_"$el"_200003_5.data $PRIMARY/. || scp user@${FILERS_LOCATION[1]}:$dir2/t1_weekly_1680_"$el"_200003_5.data $PRIMARY/. ` ; then
            :
        elseecho" scp is not successful on file $dir1/t1_weekly_1680_${el}_200003_5.data"exit 101
    done

Solution 2:

You can use

exit $?

or

exit $LINENO

to get out of shell script with non success code.

Post a Comment for "How To Exit Out Of The Shell Script With Non Zero Status If The Files Are Missing In Both The Machines?"