Crontab 2>&1 not emailing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Crontab 2>&1 not emailing
# 8  
Old 11-17-2015
Okay, well here's the less nonsense script:
Code:
#!/bin/bash

device="some name"
d=`date +"%m-%d-%Y"`
t=`date +"%T"`
voltageraw=`snmpget -v 1 -c blah 192.168.1.2 .1.3.6.1.4.1.14988.1.1.3.8.0`
voltage=`echo $voltageraw | tail -c 4`
voltfinal=$(awk -v temp=$voltage 'BEGIN { print (temp / 10) }')
tempraw=`snmpget -v 1 -c blah 192.168.1.2 .1.3.6.1.4.1.14988.1.1.3.10.0`
temp=`echo $tempraw | tail -c 4`
tempfinal=$(awk -v temp=$temp 'BEGIN { print (temp / 10) }')
tempf=`expr 9 / 5 '*' $tempfinal + 32`

thresh=23
if (( $(echo "$voltfinal < $thresh" | bc -l) )); then
        ## compile and email voltage history
        echo "Most recent voltages, last 10 samples." > /usr/src/includes/volt.txt
        echo "Samples are taken 15 minutes apart" >> /usr/src/includes/volt.txt
        echo "..." >> /usr/src/includes/volt.txt
        cmd="SELECT voltage FROM devices WHERE device_name='name' ORDER BY id DESC, time DESC LIMIT 0,10"
        mysql --user=monitor --password=blah monitor --host=localhost -e "$cmd" >> /usr/src/includes/volt.txt
        awk 'BEGIN{print "Subject:Voltage = '$voltfinal' VDC\nFrom:Voltage Tracker <me@whatever.com>"}{printf("%s\015\n", $0)}' /usr/src/includes/volt.txt | sendmail -t me@whatever.com
fi;
## put it all in a database
echo "INSERT INTO devices (DEVICE_NAME,DATE,TIME,VOLTAGE,TEMP) VALUES ('$device', '$d', '$t', '$voltfinal', '$tempf');" | mysql -u monitor -p blah monitor;

# 9  
Old 11-17-2015
To provide a log of what the script is doing (and where it's failing), set the -x and maybe -v options at the begin-of-script, remove the /dev/null redirection and have the log be mailed to you. Post the log here if need be.
# 10  
Old 11-17-2015
not sure what you mean, the script works when you run it manually, and it works when it runs from crontab, so there's no errors, it just doesn't email me.
# 11  
Old 11-18-2015
Quote:
Originally Posted by unclecameron
not sure what you mean, the script works when you run it manually, and it works when it runs from crontab, so there's no errors, it just doesn't email me.
If that is the case , then you have to set env variables in your script. Just source export PATH=${PATH}:${HOME}/bin (for eg) into your script at the top and it will work.
This User Gave Thanks to looney For This Post:
# 12  
Old 11-18-2015
@looney: yep, thanks, it worked Smilie

Here's what I used:
Code:
export PATH=${PATH}:/bin:/usr/sbin

# 13  
Old 11-18-2015
Another observation:
expr is integer, so the 9 / 5 is always 1. Consider
Code:
tempf=`expr 9 '*' $tempfinal / 5 + 32`

or use awk for higher precision (you can do int() to get an integer).
This User Gave Thanks to MadeInGermany For This Post:
# 14  
Old 11-18-2015
Thanks @MadeInGermany, that helped Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on conditional emailing

Hi All, The following databse table maintains VENDOR and EMAIL details. VENOR_NAME VENDOR_EMAIL DELL surendra@dell.com HP rajkamal@hp.com ACER sumathi@acer.com NOKIA kunal@nokia.com SONY sinu@sony.com We have to find emaild id of a vendor based... (7 Replies)
Discussion started by: ROCK_PLSQL
7 Replies

2. UNIX for Dummies Questions & Answers

Permission on crontab & mysql

HI, I am using centos 6 and finding difficultly in doing 2 below things. 1. i have a user praveen i want to allow him to create cron job of his own. so i have added his user id in cron.allow but still it is not allowing him to edit(even if i have created praveen from root user) or create his... (4 Replies)
Discussion started by: praveenkumar198
4 Replies

3. Solaris

Solaris Crontab & TOP output

Hello Guru's I'm trying to take the output of solaris top command and output to a txt file every few minutes. The issue that I'm experiencing is that I can run the following: #!/bin/bash # logfile="/usr/mvf/morris/top.log" # echo... (2 Replies)
Discussion started by: littlemorris
2 Replies

4. UNIX for Dummies Questions & Answers

What is the purpose of 2 >&1 in crontab?

while we editing the cron at the end of the cron what is the purpose of giving 2 >&1 (4 Replies)
Discussion started by: senmak
4 Replies

5. Fedora

Crontab & MAILTO

Hi there, I'm working with two servers, one with FEDORA 6 and the other one with FEDORA 7, and if I put these lines in crontab: MAILTO=MYADDRESS@mail.com */1 * * * * df -h everything works fine on FEDORA 7 , while it doesn't work on6?!?...and I find this message in the log file: MAIL... (2 Replies)
Discussion started by: Giordano Bruno
2 Replies

6. UNIX for Dummies Questions & Answers

crontab & var/spool/mai

Hi there, I'm using crontab to move some files every minute, but when crontab doesn't find these files it sends a message to the file "user_name" in the directory "var/spool/mail". Is it possible to "bypass" this problem? Thanks in advance, Giordano Bruno (1 Reply)
Discussion started by: Giordano Bruno
1 Replies

7. Shell Programming and Scripting

emailing as body of email

hi all, how do i email a file in the body of an email rather than as an attachment ?? have a ksh script which i need to read a file and email as part of the body rather than an attachment. my code is : uuencode file.log | mailx -s "test" but this sends file as an attachment. ... (2 Replies)
Discussion started by: cesarNZ
2 Replies

8. Shell Programming and Scripting

script not emailing or running

Hi, I am having trouble with this script. It is suppose to send me an email when the specified tablespace is 60% full. I run it but nothing happens FREESPACELOG=/home/oracle/scripts/bin/free_space/freespace.sql email=bob@bob.edu subject="PROD: Tablespace Free Space" cmd="mailx -s... (1 Reply)
Discussion started by: shaseeb
1 Replies

9. UNIX for Dummies Questions & Answers

Monitoring & emailing log files

Hi ..first post ! I have a Unix v445 using solaris 10. I've trolled through various web pages but can't find exactly what I'm looking for. I have an alert log...or any messages file for that matter I need to check for certain key (error type) phrases - if I find them, they are redirected to... (11 Replies)
Discussion started by: davidra
11 Replies

10. Solaris

ssh & crontab bug

Does any one knows a work around for the crontab bug when connecting using ssh to a Solaris 8 system? When you submit a crontab job through a ssh session, the job will not be executed, SunSolve has reported no fixing patches? (3 Replies)
Discussion started by: Negm
3 Replies
Login or Register to Ask a Question