Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

sudo and at commands

  • 27-04-2004 06:36PM
    #1
    Banned (with Prison Access) Posts: 13,016 ✭✭✭✭


    ok i have the follwoing two lines below that are executed from a php script on my webserver

    this line matches the ip address with the mac address of a users and enters this information in to the ip tables

    echo exec("sudo arp | grep $REMOTE_ADDR | awk '{print $1}'| /root/user/www/cgi-bin/change");

    this one does the opposite EXCEPT there is a time delay of 24 hours (i want the script to execute then)

    echo exec("sudo at now + 24 hours | sudo arp | grep $REMOTE_ADDR | awk '{print $1}'| /root/user/www/cgi-bin/rem");

    this is the one im having trouble with it works without the "sudo at now + 24 hours" but as that it just executes the command immediately!


Comments

  • Banned (with Prison Access) Posts: 13,016 ✭✭✭✭jank


    ok now i changed the order of the two lines and it seems to be working better but not fully
    the at command is working because when i do atq (find the queue of jobs) then it will show me whats wating
    but then the scripts themselves dont work it seems :(


  • Closed Accounts Posts: 294 ✭✭eggshapedfred


    i've never got the at command to work. i think it sux. you could try using the sleep command - sleep 24h. but you really don't want to do that. really.

    sorry i'm of no help


  • Registered Users, Registered Users 2 Posts: 1,186 ✭✭✭davej


    Often when you are using a job scheduler such as at, batch or the crontab the commands are run from a default shell with minimal PATH settings. Try specifying the full path to all of your commands.

    davej


  • Registered Users, Registered Users 2 Posts: 1,419 ✭✭✭nadir


    would cron not be jsut as handy? or is it not specific enough for this operation?


  • Registered Users, Registered Users 2 Posts: 1,848 ✭✭✭flamegrill


    Jank, this is a duplicate post.

    You've already been told more than once that it won't work. You can not call sudo from within a cron script its just stupid.

    use an infinite while loop started by root and use "sleep 5" within the loop to get it to check every 5 seconds and use full paths to local binaries, e.g. /usr/sbin/sudo as apposed to just sudo.

    Paul


  • Advertisement
  • Banned (with Prison Access) Posts: 13,016 ✭✭✭✭jank


    sorry about that but it was a different problem i had

    i dont get where your coming with the while loop
    all i want is to execute a command line with a time delay
    the command itself is fine but coupled with the "at" it just doesnt work

    u say i cant callled a cron script from sudo but im not using cron at all (is at a sub command of cron?) or maybe i am without knowing it!

    im new a linux so please bear with me
    if this will work any other way im open to suggestions,as im finding the "at" command very tempermental to say the least!!


  • Registered Users, Registered Users 2 Posts: 1,419 ✭✭✭nadir


    he means like this

    x=0; while [ $x -gt 0 ]; sleep 5; do echo $x; x=`echo "$x + 1" |bc`; done


  • Banned (with Prison Access) Posts: 13,016 ✭✭✭✭jank


    will i got it working eventually without the sudo command
    i more or less emdded the command i wanted in a another echo
    works perfectly now!!

    [PHP]echo exec("echo \"echo `arp | awk '/$REMOTE_ADDR/{print $1}'` | /root/user/www/cgi-bin/rem\" | at now + 1 minute");[/PHP]


Advertisement