Need help with if an extension exists in a certain repertory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with if an extension exists in a certain repertory
# 1  
Old 12-15-2012
Need help with if an extension exists in a certain repertory

Hi, I was wondering if you can help me with verifying if certain extension exists in /var/log with an if statement. Basically I'm trying to see if there is a .Gz extension in the repertory /var/log.

My code:

Code:
if [ -e /var/log/*. gz ] ; then 
echo ¨ The extension exist¨
 else 
echo ¨theres no extension¨ 
fi

^Doesn't work

Regardless if there is a .Gz extension it will echo me there's no extension...
Thanks in advance for your answers.

Last edited by Scrutinizer; 12-15-2012 at 03:09 PM.. Reason: code tags
# 2  
Old 12-15-2012
There is a space that should not be there, but also you cannot use wild cards in combination with test -e like that... Try:
Code:
exists() {
  [ -e "$1" ]
}

if exists /var/log/*.gz ; then
  echo "The extension exists"
else 
  echo "there is no extension"
fi

--
Also the double quotes are the wrong kind BTW...
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 12-15-2012
Thanks a lot Scrutinizer Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File exists or not

Dear All, I am facing a small issue in my code where in I am searching for a file in a directory and if found it sends me a message along with the time and filename. However if a file is not found based on the search pattern, the result which I am getting is all the files present in that... (7 Replies)
Discussion started by: grvk101
7 Replies

2. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

3. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

4. Cybersecurity

How to jail a process in his repertory ?

Hi all, I want to jail a process in his folder, so he can't have any link with a parent folder. Ex. If i'm a hacker, and I can upload my script & and I can start it, i'll could go to ../, /etc/passwd, etc.. So what I did is to chroot the process : I copied all libraries used by the... (1 Reply)
Discussion started by: Deb.I.am
1 Replies

5. Shell Programming and Scripting

file exists

hello, I want to know if a file exists, but do not know contador = 0 while(file$contador exists) do bla bla bla contador=$(($contador+1)) done how can i do it? thanks (4 Replies)
Discussion started by: uri_crack
4 Replies

6. Shell Programming and Scripting

File Exists

Hi, I have scenerio where i need to check 3 files whether they are of current day files and then count should not be equal to zero. how to achieve the same please let me know. Vishal (17 Replies)
Discussion started by: shady4u
17 Replies

7. Shell Programming and Scripting

While file exists with specific extension

Hi, I need some help to see if I this is posible with a while loop. I need to run a script once a day that will take all of the *.TXT files in a folder and rename them to a specific file name structure with a .dat extension. I wrote this script, but I get an error that says " line 3: too many... (2 Replies)
Discussion started by: strpwr
2 Replies

8. UNIX for Dummies Questions & Answers

Directory exists

Hi all, Sorry about this i'm sure this is a very silly question hence an easy answer but: I'm trying to write a script, part of which I want to check if a directory exists, if it doesn't then create it. Thanks for your help Tez (3 Replies)
Discussion started by: tez
3 Replies

9. Shell Programming and Scripting

process already exists

I'm attempting to modify a script that ftps files from one machine to another (see this post ). I've been testing it a few times, and once I had to kill the test because it was taking forever, and I know it wasn't working. Now, when I try to test the script again, I'm getting the following: $... (4 Replies)
Discussion started by: kadishmj
4 Replies

10. UNIX for Dummies Questions & Answers

Folder Exists

Hi, How do we check whether a folder exists already using unix script? My requirement is to check whether a folder already exists, if not create a folder else return a warning. Can anyone help me with this requirement Thanks (5 Replies)
Discussion started by: borncrazy
5 Replies
Login or Register to Ask a Question