Problem with getting shell script to look two levels down...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with getting shell script to look two levels down...
# 1  
Old 05-03-2010
Problem with getting shell script to look two levels down...

Hi,

I am writing a shell script and I need to make sure files exist two levels below a current directory so I use the following conditional check:

Code:
if [ '/var/spool/postfix/deferred/\*/\*' ]

The way the script seems to be working is that if something exists at the first level is executes the script. I only want it to execute if it is two levels below.

How can I go about doing this?

Last edited by mojoman; 05-03-2010 at 02:53 PM..
# 2  
Old 05-03-2010
I know you can use
Code:
if ls /var/spool/postfix/deferred/*/


Last edited by frans; 05-03-2010 at 04:22 PM..
# 3  
Old 05-03-2010
Quote:
Originally Posted by mojoman
I am writing a shell script and I need to make sure files exist two levels below a current directory so I use the following conditional check:

Code:
if [ '/var/spool/postfix/deferred/\*/\*' ]


That will always be successful because you are testing a non-empty string.
Quote:
The way the script seems to be working is that if something exists at the first level is executes the script. I only want it to execute if it is two levels below.

Code:
is_file()
{
  for f in "$@"
  do
    [ -f "$f" ] && return
  done
  return 1
}

if is_file /var/spool/postfix/deferred/*/*
then
   echo There are files 
else
   echo There are no files 
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script newbie, what is problem with my script?

Hello, Ubuntu server 11.10 can anybody help what is problem with my shell script? #!/bin/bash #script to find out currently logged on user is root or not. if ] then echo "You are super" else echo "You are awesome!" fi When I run script, I get following output ./uid: line 3: I... (4 Replies)
Discussion started by: kaustubh
4 Replies

2. Shell Programming and Scripting

problem in shell script

hi every body this is my first thread in this forum, i hope find a solution for my problem i have to write a script bt i still have some error and i don't know how to correct them $ for i in `seq 500 505`; do ./generateur_tache $i tache$i.txt; nprocs=$i; copt$i=`cat tache$i.txt | ./copt.awk` ;... (10 Replies)
Discussion started by: ordo_ordo
10 Replies

3. Shell Programming and Scripting

Problem in shell script

hi...i create a script which reads data from file and compare that the data which is entered by me through keyboard...i can easily read first two contents of file..i am facing the problem to read other contents.. structure of my file is username:password:username1:password1.......and so on ... (1 Reply)
Discussion started by: shubhig15
1 Replies

4. Shell Programming and Scripting

Shell script problem

i have a set of commands to be executed, which is working perfectly when executed from terminal line by line but when its put in a shell script its not working i.e its giving FileNotFoundException. how do i resolve it my code is like #!/bin/sh pushd /Desktop/Solris_Installer/ROCore jar xf... (4 Replies)
Discussion started by: divyakprabh
4 Replies

5. Shell Programming and Scripting

Shell script problem

Hello. I am trying to make this shell script bellow work on my server wich should take the names in newacc.cvs and add them to the system. For each user the script should ask me to enter a password for the user im adding and then add them to the system, however my current solution do not work atm... (7 Replies)
Discussion started by: ryzzaze
7 Replies

6. Shell Programming and Scripting

shell script , $$ problem

dialog --title "Inputbox - To take input from you" --backtitle "Linux Shell\ Script Tutorial" --inputbox "Enter your name please" 8 60 2>/tmp/input.$$ sel=$? na=`cat /tmp/input.$$` case $sel in 0) echo "Hello $na" ;; 1) echo "Cancel is Press" ;; 255) echo " key pressed" ;; ... (7 Replies)
Discussion started by: cola
7 Replies

7. Shell Programming and Scripting

C-Shell Script Problem

I am trying to write a simple script to update clients that are probes with new software, but everytime I run it, it doesn't wait for the download it just runs through the list of clients without finishing the download. I tried to use wait on the pid and I could use sleep for some crazy amount of... (0 Replies)
Discussion started by: gbxfan
0 Replies

8. Shell Programming and Scripting

call shell script from perl cgi script problem

hi,, i have perl scipt with line : system('./try.sh $t $d $m'); in shell scipt try.sh i have the line: echo $1 its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies

9. Shell Programming and Scripting

problem in shell script

I am bit new to shell scripting. Is there any body who can help me There are n number of files present in folder named like (/girish/1) ),(/girish/2) .....so on, till (/girish/24) folder. I have to delete all the file from all these folders. I have to pass '/girish' path from the file name... (5 Replies)
Discussion started by: girish.batra
5 Replies

10. Shell Programming and Scripting

Problem In Shell Script

Hi, I'm new to Shell script. Can anyone tell me where is the wrong in my code? And, my code is -- echo "Enter Start Date(YYYY-MM-DD): " read stdt echo "Enter End Date(YYYY-MM-DD): " read endt echo "Enter Flight Number(Optional): " read fln (11 Replies)
Discussion started by: satyakide
11 Replies
Login or Register to Ask a Question