shell - bash script check if file exist and sent an information email -


i worte simple script check if there files exist (endded .txt) in dirctoey older 6 hours, after check send email. scripte isnt working , expected, ask if there's simpler , more powerful way it? needs check if file eneded .txt exists , older 6hours, if yes email should sent.

this script

#!/bin/bash  date=`date +%y.%m.%d-%h.%m` hostname='host' basedir=`/usr/local/se/work/jobs/` logfile=`/usr/local/se/work/jobs/logs/jobs.log` verteiler="anyemail" # functions # # function check if jobs exists  'find ${basedir} -name "*.txt" -nmin +354' 2>$1 >>$logfile  #function mail cat << eof | mailx -s "example ${hostname} jobs `date +%y.%m.%d-%h.%m`" -a ${logfile} ${verteiler}  hi,  please check jobs.  details :  `ls -ltr /usr/local/se/work/jobs/`  ------------      end       ---------------------------------------- . thank 

to redirect stderr stdout use 2>&1, doing wrong 2>$1

also, correct parameter find -mmin not -nmin have in code.

further more have syntax errors here:

basedir=`/usr/local/se/work/jobs/` logfile=`/usr/local/se/work/jobs/logs/jobs.log` 

what mean type is:

basedir='/usr/local/se/work/jobs/' logfile='/usr/local/se/work/jobs/logs/jobs.log' 

when use backticks bash tries execute command, using right way here:

date=`date +%y.%m.%d-%h.%m` 

you not closing heredoc <<eof, need eof on last line of script.

and lose '' surrounding find command.

you should pay attention bash says, should prompt lots of errors, try run script manually see them if using via cron.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -