?
Solved

Ubuntu sudo crontab

Posted on 2014-09-08
3
Medium Priority
?
307 Views
Last Modified: 2014-09-08
Ive written a simple script which tests if the squid3 is running and if it isnt running start the service (so the file it recreated).

So I've written the script as:-
!/bin/bash
echo "Running test on Squid file"

if [ ! -f /var/log/squid3/access.log ]; then
        echo "     No Log file found"
        sendemail -t tcross@mydomain.co.uk -m "Missing Squid Log" -f "squid@missingdomain.co.uk"
        service squid3 restart
fi

Open in new window


And saved it to '/home/tcross/testLog.script', and then to run it Ive added it to crontab, so:-
sudo crontab -e
* * * * * /home/tcross/testLog.script

Open in new window


The script works great for sending me the email, but doesnt restart the service, however if I manually run the script, the service is restarted fine by using:-
sudo /home/tcross/testLog.script

I was advised to try and grep to see what the issue is:-
ps -ef | grep testLog.script
Which gives:-
tcross   31726 31523  0 14:38 pts/0    00:00:00 grep --color=auto testLog.scrip
Which apparently tells me that its running under tcross (me).

Any ideas how I can run the crontab as sudo?

Thank you in advance
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
ThomasMcA2 earned 2000 total points
ID: 40310209
Did you try adding sudo to your service command within your script?
sudo service squid3 restart

Open in new window

0
 

Author Comment

by:tonelm54
ID: 40311379
ThomasMcA2: Wont that request a password?
0
 

Author Comment

by:tonelm54
ID: 40311383
ThomasMcA2: No it doesnt (thought Id just try it)

Thank you :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question