The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 07:35 AM
command to find the path of a file abhilashnair UNIX for Dummies Questions & Answers 3 02-17-2008 07:15 PM
Setting the current path in the command prompt in (t)csh reborg Answers to Frequently Asked Questions 0 10-10-2006 03:02 PM
How to prompt for input & accept input in ONE line newbie168 Shell Programming and Scripting 2 09-27-2005 05:02 AM
find files and using them as input arguements for another command bobbygrep UNIX for Dummies Questions & Answers 1 07-18-2001 05:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-03-2008
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
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
  #2 (permalink)  
Old 01-03-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
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 {} \;
  #3 (permalink)  
Old 01-03-2008
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
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
  #4 (permalink)  
Old 01-03-2008
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
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
  #5 (permalink)  
Old 01-03-2008
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
  
 

Join Date: Dec 2007
Posts: 425
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
  #6 (permalink)  
Old 01-03-2008
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
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
  #7 (permalink)  
Old 01-03-2008
bsandeep_80 bsandeep_80 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 122
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 07:22 AM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0