Shell Script to check a file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Shell Script to check a file
# 1  
Old 10-08-2019
Shell Script to check a file

I'm required to write a simple shell script that when it runs it writes the output which is a simple barcode to a tmp flat file which I can do the bit I'm struggling with...

The next time it runs I need to check the tmp output file to see if that barcode is in the output file and if it is send out an email alert
Any help gratefully received
# 2  
Old 10-08-2019
Hi Worky,

What have you tried?

When you say "barcode" what exactly do you mean? If you want ti check the file exists then it's likely to be asimple shell test - checking the contents will be a bit more involved.

Regards

Gull04
# 3  
Old 10-08-2019
Its just an 8 char barcode in a file XA123456 in a txt file

All I want to do is check if it already exists in that file and if it does sned out an email

--- Post updated at 10:24 AM ---

The file is called failed_list
and is a flat txt file containing barcode
Code:
X1234567
X2345678
X3456789

The next time the job runs and creates failed list if there is a re occurance of a barcode I want it to mail me using mailx

Last edited by RavinderSingh13; 10-08-2019 at 09:18 AM..
# 4  
Old 10-08-2019
Hi,

Here is a code snippet, from a shell script you should be able to modify to suit quite easilly. But as you haven't shown me what you've tried or your code I can't be more precise.

Code:
### Adjust this for your environment
MAILLIST="<enter your mail address here multiple address saparated with comma(,)>"

EXIST=`grep ${BARCODE} ${TEMPFILE}`
if [ $EXIST = 0 ]
then
    echo "The Barcode ${BARCODE} already exists." >/tmp/outmail
    cat /tmp/outmail|mailx -s "Barcode Already Exists" $MAILLIST
else
    echo "New Barcode ${BARCODE} created." >/tmp/outmail
    cat /tmp/outmail|mailx -s "New Barcode Created." $MAILLIST
fi

Regards

Gull04
# 5  
Old 10-08-2019
Thanks
This was what I had

Code:
cat failed_list | xargs -I{} grep -w {} failed_list_check > failed_alert


fail_check=`cat failed_alert | wc -l`
if [ $fail_check != 0 ]
then

echo 'cat failed_alert'
mailx -s


Last edited by Scrutinizer; 10-08-2019 at 02:32 PM.. Reason: code tags
# 6  
Old 10-08-2019
Do I get you right that the new bar code string is in a file called failed_list_check and should be tested for existence in a "history" file failed_list, and, if found, send a mail? If so, try
Code:
grep -qffailed_list_check failed_list && mailx -s"something" "$MAILTO" < failed_list_check

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script file check throws [: too many arguments

While I am trying to check the filename/s in IF statement of a shell script (RedHat Linux 6) I am getting below error: File check: filename_time2=`date --date='yesterday' +%Y-%m-%d` cd /location/of/the/files/to/copy if then cp server.log-$filename_time2* ../archive/new... (5 Replies)
Discussion started by: Dip
5 Replies

2. Shell Programming and Scripting

To check whether the file is empty or not in shell script (sh)

Hi All, I need to check a file whether it exists and also whether it is empty or not. I have a code for this but it is not working as per my requirement. Can anyone pls suggest me on this. function funcFLSanityCheck { if then echo "${varFLSentFileListPath}/${varFLSentFileName}... (7 Replies)
Discussion started by: Arun1992
7 Replies

3. UNIX for Dummies Questions & Answers

Need shell script to check file

Hi Experts, I am not good in writing script. Just stared.I am looking for shell script to check following parameters. 1) Number of files on remote Linux SUSE server.- Any directory and sub directory. 2) I should define number of files in script. Files should be variable. 3) Age of... (2 Replies)
Discussion started by: ApmPerfMonitor
2 Replies

4. Shell Programming and Scripting

How to check the duplicancy of file using shell script?

Hi all, i am getting the file through sftp from a location in the name of 20141201_file.txt (iam getting the file on daily basis with date appended at the beginning) so before going to my actual process ,i want to check whether today files and yesterday file are same or not(which i used to... (3 Replies)
Discussion started by: hemanthsaikumar
3 Replies

5. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

6. Shell Programming and Scripting

How to check file name format using shell script?

Hi, I am writting a script, which accepts input file as parameter. Input file name is aa_bb_cc_dd_ee.<ext> I need to check that input file name should be of 5 fileds. Please help me out. :confused: (7 Replies)
Discussion started by: Poonamol
7 Replies

7. Shell Programming and Scripting

Need to check for empty file in C shell script

I am running a C shell script. I have an output file from a previous step and I need to run "something" in the next step to check if the file is empty. If the file is empty, then the job script should finish EOJ. If the file is not empty then the job script should abend. Please help Thanks. (4 Replies)
Discussion started by: jclanc8
4 Replies

8. Shell Programming and Scripting

need to check the file using ftp in a shell script

i need to write a shell script.. connecting to another server using ftp and check whether the file ter.txt is exists there or not. i have written scirpt partially,as i new to Unix. ftp -inv $FTPHOST > $TEMPFILE1 2> $TEMPFILE1 << EOF user $FTPUSER $FTPPW binary prompt ${CD} ls *.txt... (11 Replies)
Discussion started by: KiranKumarKarre
11 Replies

9. Shell Programming and Scripting

File System Check using shell script !!!

Hi Guys I m posing this new thread as I didnt get satisfactory result after running search here. My requirement is very simple (using shell script) I need to findout what all file systems are mounted -> Then I need check the health of that file system - by disk usage & by doing a simple... (8 Replies)
Discussion started by: csaha
8 Replies

10. Shell Programming and Scripting

Have a shell script check for a file to exist before processing another file

I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies
Login or Register to Ask a Question