LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-23-2012, 02:02 AM   #1
sukhdip
Member
 
Registered: Sep 2011
Posts: 55

Rep: Reputation: Disabled
Question small problem with ksh at aix


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:
Code:
#!/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,
 
Old 05-23-2012, 04:42 AM   #2
sukhdip
Member
 
Registered: Sep 2011
Posts: 55

Original Poster
Rep: Reputation: Disabled
As per my understanding, command is working fine i.e., find command. B'coz on RHEL machine its showing: 5_*.*: No such file or directory
but on AIX machine its showing: find: 0652-019 The status on 1_*.* is not valid.
I guess context is the same of both saying.
So what I'm thinking to do(now) that How can I put a customized message like: "No file with this name", when there is no file.
Plz help me with that.
 
Old 05-23-2012, 06:13 AM   #3
sukhdip
Member
 
Registered: Sep 2011
Posts: 55

Original Poster
Rep: Reputation: Disabled
plz help!!
Simple thing i have to do. How can I print my own message when file is not found by find command.
 
Old 05-25-2012, 12:51 AM   #4
sukhdip
Member
 
Registered: Sep 2011
Posts: 55

Original Poster
Rep: Reputation: Disabled
3-4 days to a thread....no reply for the questions what happened Unix Gurus...plz help
 
Old 05-25-2012, 01:24 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I think noone understand your script. What should do this line:
Code:
read -r filename ; echo $filename | ls -l | find "$filename"_*.* -type f ! -name ".*" | awk '{print}';
ls does not accept anything from stdin, so here: echo $filename | ls -l the red part is useless. also the | before find is meaningless. | awk '{print}' does nothing.
 
Old 05-25-2012, 01:49 AM   #6
sukhdip
Member
 
Registered: Sep 2011
Posts: 55

Original Poster
Rep: Reputation: Disabled
awk '{print}'is useless that i came to know. But ls -l is taking input from echo $filename and its printing the filenames only if the files are there. and if the files are not there it printing:
1_*.*: No such file or directory on RHEL plateform.
find: 0652-019 The status on 1_*.* is not valid. on AIX plateform.
problem is this i need to print some customized message instead of these messages. Like in Simple plain english it should say. File is not present or something like that.
how to print that my question is that...
Hope you got my point.

1_ is a randome file name, used to check.
 
Old 05-25-2012, 02:01 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Sorry, I do not understand:
Quote:
ls -l is taking input from echo $filename and its printing the filenames only if the files are there.
executing echo <anything> | ls -l will give the same result as ls -l alone (at least on RH, but I think on AIX also).
If you think it is not the case just show me how it works.
find also cannot handle pipe as input. If you want to check if $filename was valid, you would try [[ -f "$filename" ]] && find .... If you want to check if it was a directory, type [[ -d "$filename" ]] && find .....
 
Old 05-25-2012, 06:47 AM   #8
sukhdip
Member
 
Registered: Sep 2011
Posts: 55

Original Poster
Rep: Reputation: Disabled
thanks alot @pan64. u r absolutely ryt. I was using some unnecessary commands. i.e., ls,echo,awk. I'm a newbie in scripting. so from these type of experiences I will learn. as today I learned from your reply.
and somehow searching I made it to run.
again thanks for your help.
 
Old 05-25-2012, 06:49 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I'm glad to help you.







_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl one-lines within a ksh script in aix environment not excute wf201626 Programming 2 07-19-2011 03:25 PM
Force delete key to work in aix ksh ? Vilius AIX 10 05-11-2011 09:36 AM
Case Statement With Aix Ksh Scripting ']['HeBroken AIX 2 02-09-2005 12:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration