Solved

Ubuntu sudo crontab

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

823 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