Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've written a script that generates a system report.
I want to run the script (for testing) every minute, however, crontab doesn't execute it.
But the "ntpdate" command and the "service restart" command ARE working fine...
I've set the PATH variable and I'm using the full path name of the script.
When I execute the same command in the shell it works just fine...
Any advice?
About a year ago, I spent a good deal of time trying to work out why one cron event was not executed. In the end, it turned out to be the fact that the crontab did not have a blank line at the end of the file (and the event that was no executing was the last event in crontab)! I'm not sure if that problem exists in all cron implementations, but it was a very annoying error. It was only when I looked at a crontab from another machine running the same distro that I spotted the difference....
There was a problem in some of the older version of crontab on Solaris, where a blank last line would cause issues ..
On Linux and *nix systems generally I've found that removing any blank lines at the bottom usually works ..
I guess you just have to try these things; they come with experience ie the books don't usually mention them...
what user are you running cron as, and what are the permissions of the script?
I'm running cron as root (sudo crontab -e).
When I run the script at the shell without using sudo, it does work fine... (using sudo of course as well )
I would try to catch the output. (I mean next to 2>> you may need >>/home/laurent/logs/stats_HTML.stdout).
Also try to set -xv at the beginning of your script and echo some text to see it it was started.
There was a problem in some of the older version of crontab on Solaris, where a blank last line would cause issues ..
On Linux and *nix systems generally I've found that removing any blank lines at the bottom usually works ..
I guess you just have to try these things; they come with experience ie the books don't usually mention them...
Hmmm, that did not work for me... very strange though: the scripts are executable, I've created them as root, I'm running them as root in cron, but it doesn't work!
this usually caused by the special environment set by cron. That's why catching the output of those tasks may give you helpful information.
Also you can try to put an echo "hello world" > /tmp/cronjoblogfile into your scripts to see if they started. You can check the mailbox of the user, sometimes cron sends mails.
I would try to catch the output. (I mean next to 2>> you may need >>/home/laurent/logs/stats_HTML.stdout).
Also try to set -xv at the beginning of your script and echo some text to see it it was started.
#!/bin/bash
#
# This script generates a HTML file form the CSV file
#
##############################################################
# VARIABLES #
##############################################################
set -xv echo "If you see this, script $0 is executed!"
REPORT_FILE="$HOME/stats.csv"
etc.........
and
Code:
#!/bin/bash
#
# This script captures the system statistiscs and puts them in a CSV file
# We'll use this script later with the report script
#
##############################################################
# VARIABLES #
##############################################################
set -xv echo "If you see this, script $0 is executed!"
REPORT_FILE="$HOME/stats.csv"
etc..........
But both the stdout files are still empty...
BUT BUT!!
The error files are NOT empty! Let's have a look at them:
Code:
REPORT_FILE="$HOME/stats.csv"
+ REPORT_FILE=/root/stats.csv
DATE1=`date +"%d/%m/%Y"`
date +"%d/%m/%Y"
++ date +%d/%m/%Y
+ DATE1=18/05/2012
TIME1=`date +"%H:%M:%S"`
date +"%H:%M:%S"
++ date +%H:%M:%S
+ TIME1=10:44:01
#
##############################################################
# MAIN #
##############################################################
USERS=`uptime | sed 's/user.*$//' | gawk '{print $NF}'`
uptime | sed 's/user.*$//' | gawk '{print $NF}'
++ sed 's/user.*$//'
++ uptime
++ gawk '{print $NF}'
+ USERS=1
LOAD=`uptime | gawk '{print $NF}'`
uptime | gawk '{print $NF}'
++ gawk '{print $NF}'
++ uptime
+ LOAD=0.29
FREEMEM=`free -m | sed -n '2p' | gawk '(x=$4+$7) {print x}' | sed 's/$/MB/'`
free -m | sed -n '2p' | gawk '(x=$4+$7) {print x}' | sed 's/$/MB/'
++ free -m
++ sed 's/$/MB/'
++ gawk '(x=$4+$7) {print x}'
++ sed -n 2p
+ FREEMEM=866MB
IDLE=`vmstat 1 2 | sed -n '/[0-9]/p' | sed -n '2p' | gawk '{print $15}'`
vmstat 1 2 | sed -n '/[0-9]/p' | sed -n '2p' | gawk '{print $15}'
++ vmstat 1 2
++ gawk '{print $15}'
++ sed -n 2p
++ sed -n '/[0-9]/p'
+ IDLE=84
#
echo "$DATE1,$TIME1,$USERS,$LOAD,$FREEMEM,$IDLE" >> $REPORT_FILE # create the CSV file
+ echo 18/05/2012,10:44:01,1,0.29,866MB,84
REPORT_FILE="$HOME/stats.csv"
+ REPORT_FILE=/root/stats.csv
DATE1=`date +"%d/%m/%Y"`
date +"%d/%m/%Y"
++ date +%d/%m/%Y
+ DATE1=18/05/2012
TIME1=`date +"%H:%M:%S"`
date +"%H:%M:%S"
++ date +%H:%M:%S
+ TIME1=10:45:01
I think the error is located in bold, don't you think so?
Last edited by Annielover; 05-18-2012 at 03:54 AM.
yes, probably the report file is taken from root's home instead of yours. So use
REPORT_FILE="~laurent/stats.csv" or absoluthe path. You can look for another occurrences as well.
_________________________________
Happy with solution ... mark as SOLVED
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
yes, probably the report file is taken from root's home instead of yours. So use
REPORT_FILE="~laurent/stats.csv" or absoluthe path. You can look for another occurrences as well.
_________________________________
Happy with solution ... mark as SOLVED
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.