![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |