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 04: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
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 99
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  
Old 01-03-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,059
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  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 99
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  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 99
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  
Old 01-03-2008
Registered User
 

Join Date: Dec 2007
Posts: 255
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  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 99
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  
Old 01-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 99
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 04:22 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




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


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

Content Relevant URLs by vBSEO 3.2.0