Bash script for check files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script for check files
# 1  
Old 06-29-2016
RedHat Bash script for check files

I created this script for check whether specific files exist or not in the given location. but when I run this its always showing

Code:
Failed - Flag_lms_device_info_20160628.txt do not exist
Failed - Flag_lms_weekly_usage_info_20160628.txt do not exist

but both files are existing. appreciate help for fix this.


Scripts -

Code:
PREFIX="/opt/lms/sftp/ewduser/sampledata/"
REPORT="/tmp/flg_file_status-it360.txt"
DATE=$( date -d "${dtd} -1 days" +'%Y%m%d' )

rm -f "$REPORT"

            FILENAME="Flag_lms_device_info_$DATE.txt"
            FULLFN="$PREFIX/$FILENAME"            
           
            if [ -f 'find "$FULLFN"' ];then
                    echo "OK - Flag_lms_device_info_$DATE.txt exists" >> $REPORT
            else
                    echo "Failed - Flag_lms_device_info_$DATE.txt doesn't exist" >> $REPORT
            fi
			
			FILENAME="/opt/data/Flag_lms_weekly_usage_info_$DATE.txt"
            FULLFN="$PREFIX/$FILENAME"           
           
            if [ -f 'find "$FULLFN"' ];then 
                    echo "OK - Flag_lms_weekly_usage_info_$DATE.txt exists" >> $REPORT
            else
                    echo "Failed - Flag_lms_weekly_usage_info_$DATE.txt doesn't exist" >> $REPORT
            fi



Moderator's Comments:
Mod Comment Please use code - NOT color - tags as required by forum rules!

Last edited by RudiC; 06-29-2016 at 10:28 AM.. Reason: Changed COLOR to CODE tags.
# 2  
Old 06-29-2016
Why are you using "find" command in the conditions?
Check if file exists is easily done by simple using [-f "name_of_the_file"] structure.
Using condition your way you are asking if whatever output of 'find "$FULLFN"' is exists as a file, which is probably not what you want.
# 3  
Old 06-29-2016
On top of what smoofy said, the single quotes used prevent any shell expansion. I guess you want "command substitution" to take place: replace the single quotes by - deprecated - backticks or - better! - the $(...) construct.
Two more thoughts/observations:
- Do you REALLY need to prefix the absolute second file name?
- Why do you define a shell variable and then don't use it in the echo statements?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script to check the files based up on UST time.

i have 3 regions like AWS,EMEA,APJ and i use to get 3 files like a,b,c files at 3 am ust for AWS region in common shared path and x,y,z files At 10 am ust for EMEA and 1,2,3,4,5 files at 11 pm UST for APJ region. In this files name wont change daily it remain same but the file name is not same for... (2 Replies)
Discussion started by: saranath
2 Replies

2. Shell Programming and Scripting

How to check day name is it saturday in bash shell script?

How to check the day name,is it saturday in bash shell script. If dayname = saturday then run the full load else run just the incremental loads end if Thank you very much for the helpful information. (4 Replies)
Discussion started by: cplusplus1
4 Replies

3. Shell Programming and Scripting

Password check in bash script calling on expect

password check in bash script calling on expect Background: I have to copy a file from one server, to over 100 servers in a test environment. once the file is copied, it requires to have the permissions on the file changed/verified. These are all linux servers. most of them have the same... (1 Reply)
Discussion started by: 2legit2quit
1 Replies

4. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

5. Shell Programming and Scripting

bash script to check USB in linux

I need a bash script to check connected/disconnected usb with linux. I know command lsusb can be use to list down usb connect with linux. output of lsusb command is like this: Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 002: ID 0951:1643 Kingston... (1 Reply)
Discussion started by: kashif.live
1 Replies

6. Shell Programming and Scripting

bash script to check if a program is running

I'm a bit new to bash programming and I was assigned the job of writing a script that will check to see if a program server is running and to restart the program if it is not up. The script is supposed to check the program every hour (which I have looked up and I believe I know how to do) and send... (3 Replies)
Discussion started by: mcknz
3 Replies

7. UNIX for Dummies Questions & Answers

Help Running a Check in Bash Script

Hey guys, so I wrote a small script that pretty much just takes in two numbers and counts from the first to the second, e.g. unknown-hacker|544> count.sh 1 3 1 2 3 My problem is I want to make it so that if you input invalid parameters, such as non-numerical characters, more than 2... (2 Replies)
Discussion started by: Duo11
2 Replies

8. Shell Programming and Scripting

bash script to check if mounted, and mount if not

I'd like to make a wrapper bash script that will make sure that an nfs mount is mounted before launching a program that depends on the mount being active. Basically: 1) Check to see if the mount is active 2) If it's not active, try to mount it 3) If it won't mount because the nfs server is... (3 Replies)
Discussion started by: graysky
3 Replies

9. Shell Programming and Scripting

bash script to check the first character in string

Hello would appreciate if somebody can post a bash script that checks if the first character of the given string is equal to, say, "a" thnx in advance (2 Replies)
Discussion started by: ole111
2 Replies
Login or Register to Ask a Question