Problem with find command at ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with find command at ksh
# 1  
Old 05-23-2012
Question Problem with find command at ksh

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,
# 2  
Old 05-23-2012
why do you use find with "_*.*" ?
# 3  
Old 05-23-2012
This is the file name pattern. file will be in this format e.g., 1_abc.txt, 2_xyz.txt and so. thats why I'm using "_*.*"
# 4  
Old 05-23-2012
try change to this and re-try
Code:
# find -type f \( -name "$filename"_*.* -a ! -name ".*" \)

# 5  
Old 05-23-2012
Its giving me this error:

Usage: find [-H | -L] Path-list [Expression-list]

Its not even able to find the present files.:-(
# 6  
Old 05-23-2012
You probably don't have GNU find.
Try to give the path where you want to search for.

Code:
find /path/to/search -type f \( -name "$filename"_*.* -a ! -name ".*" \)

or

Code:
find . -type f \( -name "$filename"_*.* -a ! -name ".*" \)

for current directory.
# 7  
Old 05-23-2012
Quote:
Originally Posted by sukhdip
Its giving me this error:

Usage: find [-H | -L] Path-list [Expression-list]

Its not even able to find the present files.:-(
can you add a path
Code:
# find $PATH -type f \( -name "$filename"_*.* -a ! -name ".*" \) ....

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh script find command not printing any results

Hello, Hitting a wall on this one. When at the command prompt it works fine: # find /home/testuser -name 'PAINT*canvasON.txt' /home/testuser/PAINT_canvasON.txt # pwd /home/testuser # ls -l PAINT*canvasON.txt -rw-r--r-- 1 root user 23 Feb 07 02:58 PAINT_canvasON.txt... (2 Replies)
Discussion started by: seekryts15
2 Replies

2. Shell Programming and Scripting

find command to move the files to other folder - ksh 88

Hi , I've learnt that the following command will remove the files from the given folder for given no.of days find /home/etc -type f -atime -10 -exec rm -f {} \; But how can I change the above command that will move the files to another specified directory instead of removing the... (1 Reply)
Discussion started by: smile689
1 Replies

3. Shell Programming and Scripting

Regular Expression in Find command [KSH]

Hello, I am trying to use regex wtih find command in KSH. For some reason it is not working as expected. Input: comm_000_abc_0102.c comm_000_abc.c 456_000_abc_1212.cpp 456_000_abc_.cpp Expected Output: comm_000_abc_0102.c kkm_000_abc_8888.cpp (Basically I want to find all... (6 Replies)
Discussion started by: vinay4889
6 Replies

4. Shell Programming and Scripting

ksh - find command with 2 actions attached and error logging

Hi there, I'm encountering problems on an AIX system when using following in my script. find . -name *.edi -type f -exec sh -c 'scp {} $user@$server:$path || exit 5; mv {} $sent || exit 7' \; the error i get is following find: 0652-018 An expression term lacks a required... (4 Replies)
Discussion started by: Kerberos
4 Replies

5. Shell Programming and Scripting

problems with ksh array and find command

set -A allfiles `find $usrhtml -type f` i am trying to populate this array with the find command. It works fine when find is looking through a single directory but when i add a new subdirectory the files in the subdirectory get duplicated. Can anyone help me and fix this so each files in... (1 Reply)
Discussion started by: bjhum33
1 Replies

6. Shell Programming and Scripting

Help - Using Find command on dynamic files on KSH

Hi Forum. When I run the following find command, I get the desired results: find . \( -name a.out -o -name '*.o' -o -name 'core' \) -type f -ls I want for my script to dynamically calculate and assign a variable var1 to contain all the files that I want to search instead of hard-coding. ... (2 Replies)
Discussion started by: pchang
2 Replies

7. Shell Programming and Scripting

problem with KSH script: command line args

Hi I am executing a KSH script by passing command line arguments example: Red Green Dark Red Blue when I am splitting the arguments by using " "(Space) as delimiter But the colour Dark Red is a single parameter. But it is getting splitted in between How to avoid this. Please help Also... (4 Replies)
Discussion started by: hemanth424
4 Replies

8. Shell Programming and Scripting

Problem with embedded FTP command in Ksh - System Cannot find the specified path.

I have the following FTP embedded in a Ksh script on AIX 5.3 ftp -n <<WHATEVER open 10.101.26.218 user hcistats ******* ascii put $thupdatefile put $thcollectfile quit WHATEVER Here is what my script returns: ... (3 Replies)
Discussion started by: troym72
3 Replies

9. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

10. UNIX for Advanced & Expert Users

find command from shell scipt (ksh) problem

Hi experts, I have a simple shell script as follows. #!/bin/ksh FIND_STRING="\( -name 'testfile*.Z' -o -name 'DUMMY_*' \) " find /tmp -type f $FIND_STRING -print When I run this with ksh -x testscript, I get the following output. + FIND_STRING=\( -name 'testfile*.Z' -o -name... (6 Replies)
Discussion started by: kodermanna
6 Replies
Login or Register to Ask a Question