Solved

Ubuntu sudo crontab

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
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,…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

695 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