Check presence of trigger file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check presence of trigger file
# 1  
Old 06-12-2013
Check presence of trigger file

Hi,
I make a sftp connection successfully.My requirement is the script shall execute only after i find a trigger file(dailyreport.OK.psv) in the remote dir. If the trigger file is not present ,the script should exit else it should continue with the rest of the scripts statements. Below code is having an issue in the if condition. Need help with this.

Code:
sftp samuser@q15server <<END_SCRIPT
if [! -f /common/XPU0/PDS/*OK*] ; then
exit 0
fi
lcd /app/reporting/daily/temp
get /common/XPU0/PDS/*OUT*.psv
quit
END_SCRIPT
sort -u -t'|' -k1,1r /app/reporting/daily/temp/*OUT*.psv
exit 0


Last edited by Scott; 06-12-2013 at 02:04 PM.. Reason: Code tags, not ICode tags
# 2  
Old 06-12-2013
sftp is not shell. It does not have 'if'.

Run sftp to retrieve the file(s), and see if you have it locally.
# 3  
Old 06-12-2013
I tried removing if outside of the sftp and made the below modification. The script is not able to find OK and gives a message as
Code:
sftp> ./test.sh[13]: ![/app/reporting/daily/temp/*OK*]:  not found

My aim is to check the presence of this .OK file .If its present then i execute the rest of the statements else i quit . The script looks like :

Code:
sftp samuser@q15server <<END_SCRIPT
lcd /app/reporting/daily/temp
get /common/XPU0/PDS/*OK*
get /common/XPU0/PDS/*OUT*.psv
quit
END_SCRIPT
if ![/app/reporting/daily/temp/*OK*];then
exit 0
fi
sort -u -t'|' -k1,1r /app/reporting/daily/temp/*OUT*.psv
exit 0

# 4  
Old 06-12-2013
You can't cram an if-statement together like that, spaces are needed around each token.

Also, you need if [ -f filename ] to look for a filename. But it takes one, and only one filename -- not zero, not three, one. So if * finds more than one file that's a syntax error.

Keeping that in mind I'd try this:

Code:
if ls /app/reporting/daily/temp/*OK* 2>/dev/null
then
...
fi

This uses an external utility, ls, so [ ] aren't needed. The point of this is that you can cram multiple files into ls and it's not an error, but if there's zero files, it will be fed the string /app/reporting/daily/temp/*OK* and will return error because that filename doesn't exist.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 06-12-2013
Thanks the ls worked Smilie. Incase i do have a specific file and i wish to check , i tried using the following code but it gave a exception

sftp> ./test.sh[13]: ![-f: not found

Code:
if ![-f /app/reporting/daily/temp/abc.OK];then
echo "No ok file"
fi
exit 0

# 6  
Old 06-12-2013
Again, you need spaces around those [ ] , you can't just jam it all together.

Code:
if ! [ -f /app/reporting/daily/temp/abc.OK ] ; then
echo "missing"
fi

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 06-14-2013
I want to add the total count of actual records which i want to add as a footer at the end. When i execute the script below i get RECORd_COUNT along with the file name .

Code:
sftp samuser@q15server <<END_SCRIPT
lcd /app/reporting/daily/temp
get /common/XPU0/PDS/*OK*
get /common/XPU0/PDS/*OUT*.psv
quit
END_SCRIPT
if ![/app/reporting/daily/temp/*OK*];then
echo "File missing"
exit 0
fi
sort -u -t'|' -k1,1r /app/reporting/daily/temp/*OUT*.psv
COUNT=$( wc -l) /app/reporting/daily/temp/*OUT*.psv
echo "RECORD_COUNT="$COUNT >> /app/reporting/daily/temp/*OUT*.psv
exit 0

Output is
Code:
RECORD_COUNT= 7 /common/pzuz058/XPU0/PDS/final.psv


How can i avoid the file name coming in the out for the record count ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file presence and delete other file

Hello, I have file all_file.txt at the end of process this file all_file.txt should be deleted only if there is no file present in dir /all_file/tmp/ or in it's sub directory. can you please help me with the peace of code for this. Thanks (2 Replies)
Discussion started by: kumar30213
2 Replies

2. Shell Programming and Scripting

Identifying presence and name of new file(s)?

I have an HP-UX server that runs a script each night. The script connects to an SFTP server and downloads all xml files (if any are present) from a certain folder, and then deletes the files from the SFTP server. So sometimes it will download a new file, sometimes it will download 2 or 3 new... (4 Replies)
Discussion started by: lupin..the..3rd
4 Replies

3. Shell Programming and Scripting

Check the presence of file >size?

Hi, Following script work fine: #!/bin/bash FILE=$1 if ; then echo Yay else echo Boo fi But I would like to add another condition that if FILE... (3 Replies)
Discussion started by: nrjrasaxena
3 Replies

4. UNIX for Dummies Questions & Answers

Match the amount fields in the source file vs trigger file

Hello, I have to write a script to compare the sum of the amount fields in a source file and the amount field in another file. details are: based on the name of the source file (say SALES as an example), a file already available in a path will be grabbed (say SALES_ParmFile) and this file... (4 Replies)
Discussion started by: vijaylak
4 Replies

5. Shell Programming and Scripting

check file for presence of set of strings

hi everybody, I need a quick help with this issue. I have configuration file in which the following set of strings must be present. I need to check it with the bash script (leading spaces are not significant). Check must be case insensitive. Can anybody help? ... any lines <SECTION... (4 Replies)
Discussion started by: sameucho
4 Replies

6. OS X (Apple)

command to check presence of volume

Hi: I'm not really a programmer, but I've created a small logout hook script to copy some specific directories to a server volume when a user logs out (10.6.4). These is a laptop user, so I'm looking find: 1) the command to check if the volume (including path to directory?) is available. ... (1 Reply)
Discussion started by: kevinmmac
1 Replies

7. Shell Programming and Scripting

check presence of input file

My script is taking a file "input.in" as input for running the script. My worry is that i need to execute the script only if the file is present, if it's not don't perform the next commands. Just to have a check at the beginning of the script : If "input.in" exists, then go on. If it's does not... (4 Replies)
Discussion started by: newpromo
4 Replies

8. Shell Programming and Scripting

Polling continously for presence of a file

Hi, My os is sun solaris 5.10 and Korn shell scripting. I have a file name like CCNA_EARLY_SWP.w062309 where 062309 is date in mmddyy .This is the value date of the file.(will I need to check continously from 5.00 - 7.00 am daily for this file . If the file has not come at 5 am or 7am... (4 Replies)
Discussion started by: manoj39
4 Replies

9. Shell Programming and Scripting

Check if trigger Script is running

HI, I have a script which will be running all the time...it is like a trigger.. wakesup every 10 minutes(trigger.sh) executes, and I want to write another script which monitors this script every one hour and if it finds that trigger script is not running it should start it and exit...and here... (9 Replies)
Discussion started by: mgirinath
9 Replies

10. UNIX for Dummies Questions & Answers

How do I test for the presence of a file in Bourne Shell

How do I test for the presence of a file in Bourne Shell (3 Replies)
Discussion started by: vins
3 Replies
Login or Register to Ask a Question