Solved

Ubuntu sudo crontab

Posted on 2014-09-08
3
289 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 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
winscp where are logs stored 3 73
awk variable in printf 1 42
Upgraded from Debian 7 to 8.7 and got black screen 20 98
NTPD Client Port Usage 12 65
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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