Check file if not found send mail if exit call second script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check file if not found send mail if exit call second script
# 1  
Old 10-10-2018
Check file if not found send mail if exit call second script

I need to check my script and change to working mode. currently it was not sending the mail and exit without calling the second script.

I need to check the file is present ="/home/Rvtools/test.csv"

if this file not found after the time retry send mail file not found
If the file exit run the second script and exit


Code:
cp /home/Rvtools/data/full/*.csv /home/Rvtools/test.csv 2> /home/Rvtools/error_outputs

counter=0
while [ ! -e /home/Rvtools/test.csv ]; do
      sleep 5
      counter=$((counter+1))
      if [$counter -ge 3 ]; then
      echo "file not found"| mailsend -f test@google.com -smtp IP -t test2@user.com -sub "Capacity_Report_$DATE_error" -attach "D:\brocade\cygwin\home\Rvtools\error_outputs" 
      else
      exec /home/Rvtools/vmware-capacity-V2.sh
      fi 
done

# 2  
Old 10-10-2018
Trying to interpret your description of your script's behaviour, I'd infer that /home/Rvtools/test.csv exists from the beginning and the while loop is not entered at all. Run your script with the xtrace (-x) option set, and, if you're still stuck, post the output here for further analysis.



Be aware that the cp command fails with cp: target 'YY' is not a directory if multiple *.csv source files exist.
Be aware that the exec command "replaces the shell. No new process is created." (c.f. man bash). Execution won't come back to your above scipt to finish the while loop and execute any eventual further code after the loop.
You might want to check your logics within the while loop, as - once the condition is true - nothing happens in the loop to modify that. Are you waiting for a background process to make that file appear somehow?
# 3  
Old 10-10-2018
Code:
Be aware that the cp command failes with cp: target 'YY' is not a directory if multiple *.csv source files exist.
You might want to check your logics within the while loop, as - once the  condition is true - nothing happens in the loop to modify that. Are you  waiting for a background process to make that file appear somehow?

No i have checked this is file not director I am just copying the file to another director.

Or is it possible the check the error file

Code:
/home/Rvtools/error_outputs

if you find string "No such file or directory" wait for three time if not found then send mail file not found and exit the script

If file file found run the second script
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write this script:- check output word and send a mail?

Hi Guys, I am not Good at scripting. I need to write a script such that if output of command shows the particular word in output then send mail to abc@compay.com -bash-3.2$ ps -ef | grep bpbkar root 6040 1 0 13:05:19 ? 0:00 bpbkar -r 2678400 -ru root -dt 47395 -to 0... (20 Replies)
Discussion started by: manalisharmabe
20 Replies

2. Shell Programming and Scripting

How to call mail id from different file in shell script?

Hi Team, Please can anyone tell me how to call mail ids from different file in shell script. For Example: ========= export MAILX=/bin/mailx export MAIL_DBA=xxx@gmail.com,yyy@gmail.com,zzz@gmail.com sendalertmess() { MESSAGE="ALARM" echo $MESSAGE | MAILX -s "uname -n :Oracle error"... (3 Replies)
Discussion started by: indira_s
3 Replies

3. Shell Programming and Scripting

check postfix deferred mail and send notification script

Hi Guys, I have a postfix server which is deferring emails. Now I need to send notification to a specific email address if: The sender of the deferred email is: abc@example.com Contains specific subjects: a file (/opt/subjects) contains all the subjects in place Then need to send a... (0 Replies)
Discussion started by: linuxrulz
0 Replies

4. Shell Programming and Scripting

Check the exit status in a pipe call

Guys, I have a problem :confused: and I need some help: I've to process many huge zip files. I'd code an application that receive the data from a pipe, so I can simple unzip the data and send it (via pipe) to my app. Something like that: gzip -dc <file> | app The problem is: How can I... (7 Replies)
Discussion started by: Rkolbe
7 Replies

5. Shell Programming and Scripting

Check file and if it doesnt exist , exit script

Hi, Another problem, here is my code #!/bin/sh dir='/opt/apps/script/CSV' datadir='/opt/apps/script/data' while : ; do ls -1rt $dir/*.csv > /dev/null 2>&1 if ;then cp $datadir/weekly.txt $dir/weekly.csv else exit 0 fi done (10 Replies)
Discussion started by: tententen
10 Replies

6. UNIX for Dummies Questions & Answers

unix script to check if rsh to box and send status mail

rshstatus=`rsh -n lilo /db/p2/oracle/names9208/restart_names.sh` if $rshstatus <>0 then errstatus=1 mailx -s "xirsol8dr" ordba@xxx.com >> $log_dr else if errstatus=0 echo "status to xirsol8dr successful" can anyone provide if this is t he correct way to do this or is there a better way? (1 Reply)
Discussion started by: bpm12
1 Replies

7. UNIX for Advanced & Expert Users

Script which can send file to diffrent mail ids.

Hi i am looking for the script which can send file to different mailids, please halp me out. Thanks in advance. (3 Replies)
Discussion started by: vpandey
3 Replies

8. Shell Programming and Scripting

script to find a file and send a mail

I need a shell script which checks for a file in a particuler folder and should send me a mail if the file of that name is present. Please help me on this.I am new to shell scripting. (6 Replies)
Discussion started by: jayaramanit
6 Replies

9. Shell Programming and Scripting

How to attach a file & send mail thru script

In shell script how can I attach a file and send a mail. suppose if I written like the following way usr/bin/mail 'subject" "mail_id" < file. a mail goes to the mail-id with the content of file.But I want the file to be atttached to the mail.How can I get it.is there any way for this. ... (9 Replies)
Discussion started by: Mar1006
9 Replies

10. Linux

Unable to send mail - but no errors found :-(

Hi Guys I am using this version of Linux box (as shown below). I am unable to send email from the box. But I am not getting any errors while sending email. :mad: Any idea what could be the reason? What entry should I check? :confused: $ uname -a Linux machine-name 2.4.21-144-smp4G #1... (6 Replies)
Discussion started by: csaha
6 Replies
Login or Register to Ask a Question