Hi!
I made a shell script which is offering menu choice. I made it on RHEL & then with little bit changes I was able to run successfully on AIX/ksh.
Script is working fine with no issues other than a little one i.e., There is one choice in which I can list out and delete some files from a directory as per userinput. If there are files it listing and deleting without any problem but if there ain't any files then its displaying one error.
i.e.,
find: 0652-019 The status on 1_*.* is not valid.
Here is my script:
#!/usr/bin/ksh
script_menu() {
while :
do
clear
echo ----------------------------------------------
echo ************Script Start Menu************
echo ----------------------------------------------
echo Run from the following Scripts
echo
echo [1] xyz.sh
echo [2] abc.sh
echo [3] Return to Main Menu
echo [4] Exit
echo ----------------------------------------------
read choice
case $choice in
1)
echo Run xyz script file; /backup/test1/xyz.sh;
echo Press Enter;
read x;;
2)
echo Run abc script file; /backup/test1/abc.sh;
echo Press Enter;
read x;;
3)
return;;
4)
exit;;
esac
done
}
#Main Menu
while :
do
clear
echo ----------------------------------------------------
echo ******************Main Menu******************
echo ----------------------------------------------------
echo Select a Choice
echo [1] Run the Scripts
echo [2] View the Current Run Numbers
echo [3] Amend the Run Numbers
echo [4] Check Status of propagation
echo [5] Turn Propagation on or off
echo [6] View Log Files
echo [7] List files in import directory
echo [8] Clear files from import directory
echo [9] Exit
echo ----------------------------------------------------
echo Select choice {1-9}:
read choice
case $choice in
1)
script_menu;;
2)
echo Current Run Number; cat /backup/test1/run_number.txt;
echo Press Enter;
read x;;
3) echo Enter Run Number;
read -r userinput; echo $userinput > run_number.txt;
echo Press Enter;
read x;;
4)
echo Propagation Status ; cat /backup/test1/auto_pro.txt;
echo Press Enter;
read x;;
5)
echo Change Propagation ; echo Enter Value; read -r userinput; echo $userinput > auto_pro.txt;
echo Press Enter;
read x;;
6)
echo View Log files;
echo Enter Log file name;
read -r filename ; echo $filename | ls -l | find "$filename"_*.* -type f ! -name ".*" | awk '{print}';
echo Press Enter;
read x;;
7)
echo List files in import directory;
echo Enter file name;
read -r filename ; echo $filename | ls -l | find "$filename"_*.* -type f ! -name ".*" | awk '{print}';
echo Press Enter;
read x;;
8)
echo Clear files from import directory;
echo Enter File Name;
read -r filename ; echo $filename | ls -l | find "$filename"_*.* -type f ! -name ".*" -exec rm -f {} \;
echo Press Enter;
read x;;
9)
exit;;
*)
echo Invalid Number
esac
done
option number 6,7,8 are giving above error, If there is no files with the name as input by user.
How can I solve this? Plz help !!
Thanks,