Solved

Ubuntu sudo crontab

Posted on 2014-09-08
3
268 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
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
ThomasMcA2 earned 500 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now