0

I have a simple script and asking crontab to execute that script. In the script, I have 2 commands I want to run and append the output to a file. Only one of the commands does as it should. However, if I run the script myself as 'root', the script works. All the machines, RHEL, Ubuntu Server/Desktop and Fedora have the same outcome. Below is my script and crontab -l.

I have been researching and trying everything, even setting the $PATH, but nothing. The service httpd status will not run.

#!/bin/bash

#check httpd status and append to file
service httpd status >> /path/to/file;

#check cupsd status and append to file
netstat -punta | grep cupsd >> /path/to/file;

exit

Crontab:

*/1 * * * * /usr/local/bin/script.sh
9
  • #!/bin/bash #check httpd status and output to file service httpd status >> /var/log/messages; #check pptpd status and append to file netstat -punta | grep cupsd >> /var/log/messages; exit
    – chris
    Jun 10, 2015 at 1:34
  • personal crontab? You might (probably don't) have permission to write to /var/log/messages.
    – Grizly
    Jun 10, 2015 at 1:36
  • the netstat command will write. if i run the script, it runs correctly
    – chris
    Jun 10, 2015 at 1:42
  • output from 'root' running script [root@localhost ~]# /usr/local/bin/services_1.sh Redirecting to /bin/systemctl status httpd.service [root@localhost ~]# cat /var/log/messages ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled) Active: inactive (dead) tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1975/cupsd tcp6 0 0 ::1:631 :::* LISTEN 1975/cupsd
    – chris
    Jun 10, 2015 at 1:45
  • 1
    /var/log/messages is a syslog file; you should not be overwriting this with anything. Jun 10, 2015 at 2:45

1 Answer 1

1

Solution:

Instead of running 'service httpd status' run '/etc/init.d/httpd status

This has worked flawlessly. What keyed me onto this was attempting to run this in Ubuntu 14.04.2 LTS, I looked at the cron log for errors, found the errors online and substituted the above.

Not the answer you're looking for? Browse other questions tagged .