LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-22-2014, 02:21 PM   #16
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,501

Rep: Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431

[ -f /deployment/*.failed ] will not work if there were more than one *.failed files in that dir.
to check if there is a file named .*failed simply call ls:
ls /deployment/*.failed >/dev/null 2>/dev/null && { #here comes the code, there is a file (at least one) }
 
2 members found this post helpful.
Old 06-22-2014, 02:45 PM   #17
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,667
Blog Entries: 10

Rep: Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076
Quote:
Originally Posted by pan64 View Post
[ -f /deployment/*.failed ] will not work if there were more than one *.failed files in that dir.
to check if there is a file named .*failed simply call ls:
ls /deployment/*.failed >/dev/null 2>/dev/null && { #here comes the code, there is a file (at least one) }
Good point. I was a little unsure myself as he said:
Quote:
Originally Posted by apss_evaluator View Post
if apps on my jboss deployment directory has no ".failed" extension files on that directory
plural.

I really should pay more attention or ask for more exacting information.

But it's a "we" thing, not a "me" thing.

Thanks!
 
1 members found this post helpful.
Old 07-10-2014, 03:52 PM   #18
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
Good point. I was a little unsure myself as he said:

plural.

I really should pay more attention or ask for more exacting information.

But it's a "we" thing, not a "me" thing.

Thanks!

Hi,

I retried again updating the script, I sampled the deployments directory has 3 ear files with .failed deployments.

I got this results:

./script.sh: line 3: [: /tmp/deployments/app01.ear.failed: binary operator expected



the script now is:
#!/bin/bash
log_file=/tmp/deploy.log
if [ -e /tmp/pg_pid.txt ] && [ -e /tmp/jboss7_pid.txt ] && ! [ ls /tmp/*.failed ] && grep -Fqi "TIMEOUT" "$log_file"; then
echo "OK"
else
echo "NOT OK!"
fi
 
Old 07-11-2014, 01:44 AM   #19
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,501

Rep: Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431
you cannot put the ls command into [ ] - ok, you can, but will not work that way. To check if there was a file named *.failed in /tmp you need to check the return code of ls (like you used grep, without [ ]). But you will hardly put all these conditions in a single line. So you can try something like this:
Code:
a=0
[ ! -e /tmp/pg_pid.txt ] && (( a++ ))
[ ! -e /tmp/jboss7_pid.txt ] && (( a++ ))
ls /tmp/*.failed || (( a++ )) 
grep -Fqi "TIMEOUT" "$log_file" || (( a++ ))

if [ $a == 0 ]; then
echo "OK"
else
echo "NOT OK!"
fi
 
1 members found this post helpful.
Old 04-29-2015, 01:02 PM   #20
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
you cannot put the ls command into [ ] - ok, you can, but will not work that way. To check if there was a file named *.failed in /tmp you need to check the return code of ls (like you used grep, without [ ]). But you will hardly put all these conditions in a single line. So you can try something like this:
Code:
a=0
[ ! -e /tmp/pg_pid.txt ] && (( a++ ))
[ ! -e /tmp/jboss7_pid.txt ] && (( a++ ))
ls /tmp/*.failed || (( a++ )) 
grep -Fqi "TIMEOUT" "$log_file" || (( a++ ))

if [ $a == 0 ]; then
echo "OK"
else
echo "NOT OK!"
fi
I used the example above and replaced "a" as "j" but I got this on the result

[user@ewan bin]$ ./restart_jboss.sh
./restart_jboss.sh: line 418: [: too many arguments

Last edited by apss_evaluator; 04-29-2015 at 02:30 PM.
 
Old 04-30-2015, 01:29 AM   #21
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,501

Rep: Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431
I have no idea which one is line 418
probably you need to write:
if [ "$a" == 0 ]; then
 
1 members found this post helpful.
Old 05-03-2015, 07:02 PM   #22
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
I have no idea which one is line 418
probably you need to write:
if [ "$a" == 0 ]; then
yup that was the changes I made and it worked out. thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if file exists in C MTK358 Programming 17 06-20-2010 03:40 AM
Check File Exists shady4u Linux - General 2 02-21-2010 04:05 AM
[SOLVED] check whether a file exists or not ?? vikas027 Programming 5 06-05-2008 05:45 AM
bash check folder exists zerocool22 Programming 22 06-01-2008 08:53 AM
c++ check if file exists Genjix Programming 3 03-15-2004 01:08 AM


All times are GMT -5. The time now is 03:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration