0

I added this rule to the bottom of my crontab

* * * * * /root/test.sh

It basically resets iptables so I can fool around. If I mess up I won't be locked out of my box. When I run the script in bash writing /root/test.sh it clears everything as expected. However if I wait a minute it doesn't seem to execute.

I ran the command below and can see every minute it appears to run my script but my script isn't doing anything.

grep CRON /var/log/syslog

IIRC the way to force a script to run as the owner is chmod a+s file. So I did that. stat shows this line

Access: (6755/-rwsr-sr-x)  Uid: (    0/    root)   Gid: (    0/    root)

Shouldn't cron be running my script as root? Why doesn't it seem to be executing? I am running debian 7 (wheezy)

1 Answer 1

2

You cannot run a scripts (as opposed to a binary) with SUID permission. Your script is executing, but as your user, not as root, so its iptables calls aren't working.

Error messages from cron jobs go to local email. Make sure that local email is configured properly (some distributions don't do it by default).

The easy solution (since you have root access) is to install that script in the root user's crontab, or alternatively in /etc/crontab using the line:

* * * * * root /root/test.sh
4
  • How do I do that? I tried writing that earlier in crontab -e but it didnt appear to work either
    – user4069
    Commented Nov 11, 2014 at 7:15
  • use vi /etc/crontab
    – Archemar
    Commented Nov 11, 2014 at 7:19
  • This worked. Although I wasn't sure what I need to do to 'update cron' so I did crontab e and commented out an old line. One thing that confuses me is I dont see an obvious line that runs scripts on a minute basis.
    – user4069
    Commented Nov 11, 2014 at 7:22
  • @acidzombie24 crontab -e should work after sudo -s -H, or alternative directly edit the system /etc/crontab and use the alternative format. cron doesn't need updating, it will check every minute if the /etc/crontab, or the files in /var/spool/cron have been touched.
    – Anthon
    Commented Nov 11, 2014 at 7:28

You must log in to answer this question.