Here's my simple runme.sh:
#!/bin/bash
/bin/echo 'CbEYKFKt' | /usr/bin/sudo -S /bin/su -c "whoami;/etc/init.d/iptables stop"
In which, 'CbEYKFKt'
is the password for current user: samX, who has the root privilege (have appended "samX ALL=(ALL:ALL) ALL"
in visudo
). I intend to stop iptables at a specific time in crontab, but nothing happened to iptables service when the time is up. Nevertheless, if I execute bash runme.sh
, it will works fine.
My crontab is as follows:
58 16 * * * /bin/bash /home/data/samX/runme.sh 2>&1 > /home/data/samX/log_cron
Nothing will be printed to log_cron file. Is there anything wrong with my code? Thanks in advance.
P.S.
A error is printed after I moved 2>&1
to the end:
sudo: sorry, you must have a tty to run sudo
Does anyone know what's that mean?