The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
create PATH from find command output rein UNIX for Dummies Questions & Answers 3 04-01-2008 04:35 AM
command to find the path of a file abhilashnair UNIX for Dummies Questions & Answers 3 02-17-2008 03:15 PM
Setting the current path in the command prompt in (t)csh reborg Answers to Frequently Asked Questions 0 10-10-2006 12:02 PM
How to prompt for input & accept input in ONE line newbie168 Shell Programming and Scripting 2 09-27-2005 02:02 AM
find files and using them as input arguements for another command bobbygrep UNIX for Dummies Questions & Answers 1 07-18-2001 02:24 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 98
Help-prompt for path and take this as input in find command

HI ,

I am trying to wite a script that will prompt me saying " what is path that you want to find ?". once i specify the path, the script should put this path in the find command mentioned below and execute the script:

find <path> -ctime +200 -type f -exec ls -l {} \;


for example :

Imagine i have script called shell.sh, when i run this it should ask me in the prompt saying "what is path that you want to find ?"

when i specify some path like : /usr/local/

then it should take this as input in the find command in the script like below and give me the results:

find /usr/local/ -ctime +200 -type f -exec ls -l {} \;



Can someone help me out?

Thanks,
Sandeep
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-03-2008
Moderator
 

Join Date: Dec 2003
Location: /ksh93
Posts: 886
This sounds suspiciously like homework but in the offchance that it is not
here is one way of doing it:

Code:
#!/bin/ksh

read dir?"what is the path that you want to find ?"

find $dir -ctime +200 -type f -exec ls -l {} \;
Reply With Quote
  #3 (permalink)  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 98
hi thanks very much...being frank its not a homework question ...i am just trying to figure out something that i will need in future
Reply With Quote
  #4 (permalink)  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 98
Hi ,

i created a sheel script with what you had specified and then ran it as sandeep.sh as below

This does not work...it gives me error as follows:

[root@bon05 EA]# sandeep.sh
-bash: sandeep.sh: command not found


************************************************
##!/usr/bin/sh -x

read dir?"what is the path that you want to find ?" > /EA/sandeep.log

find $dir -ctime +200 -type f -exec ls -l {} \; >> /EA/sandeep.log

*****************************************************


Please help
Reply With Quote
  #5 (permalink)  
Old 01-03-2008
Registered User
 

Join Date: Dec 2007
Posts: 208
use the korn shell as in the script that he posted. #!/bin/ksh or whatever the path is to ksh on you machine.

you probably should run the script by ./sandeep.sh as the directory is probably not in your $PATH
Reply With Quote
  #6 (permalink)  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 98
Thanks ...just one more thing ....what if a user just not supply any path to the question , can i add that check in the script...if so how can i do that?..thanks again
Reply With Quote
  #7 (permalink)  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 98
This is how my program looks can you please tell me why i am getting errors when i run the script as

$./sandeep.sh
./sandeep_new.sh: line 12: read: `dir?what is the path that you want to find ?': not a valid identifier

./sandeep_new.sh: line 13: read: `dir?Please specify a valid path to search ?': not a valid identifier
./sandeep_new.sh: line 23: syntax error near unexpected token `else'
./sandeep_new.sh: line 23: `else'


#!/bin/ksh

NULL=""; export NULL #If the user specifies NULL value

echo "The cvs file script has started............................................"
read dir?"what is the path that you want to find ?"
read dir?"Please specify a valid path to search ?"

if [ "$dir" = "$NULL" ]; then
echo "Not a Valid path or path not specified by user,Do you wish to continue:"[Y/N]?""
read ans
case "$ans" in
y*|Y*)

read log?"Please specify a valid log file(ex:/logs/sandeep.log) that needs to created that will dump the results on the log file ?"

else
n*|N*)
echo exiting from program...;;
esac

if [ "$log" == "$NULL" ]; then
echo "Not a Valid path or path not specified by user,Do you wish to continue:"[Y/N]?""
read ans
case "$ans" in
y*|Y*)

read days?"Please specify the valid number as the number of days for the serach ?"
if [ "$days" == "$NULL" ]; then
echo "Not a Valid path or path not specified by user,Do you wish to continue:"[Y/N]?""

read ans
case "$ans" in
y*|Y*)

find $dir -ctime +$days -type f -exec ls -l {} \; > $log

else
n*|N*)
echo exiting from program...;;
esac


fi
fi

fi



exit

Last edited by bsandeep_80; 01-03-2008 at 03:22 AM.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0